TTPhotoViewController get current center image? - iphone

Is there a way to get a current image to an object of UIImage? I have tried casting TTPhoto to UIImage, but it doesn't work.

I did this differently. My Photo source is generated using JSON data so I couldn't use the method above as the photo source is different every time. Instead I used the URLForVersion method on TTPhoto to download the image into a UIImage.
NSURL *imageURL = [NSURL URLWithString:[self.centerPhoto URLForVersion:TTPhotoVersionLarge]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];

I figured it out. We can use TTPhotoViewController's instance variable centerImageIndex. This will give us the index of the current image.

Related

iPhone NSMutableArray loading background image from url

I have a NSMutableArray where it stores url to a image. And this NSMutableArray is called userPic. From my server it only prints out the url: not JSON or anything, only the url.
I can see in the output in Xcode that it shows the url, but how to I get this url in userPic to a background? Im trying to addSubView with the image for a background.
If something is unclear, sorry about that. Just let me know.
Please try to use this one.And i think your URL at index 0 of your array.
NSURL *imgURL = [NSURL URLWithString:[userPic objectAtIndex:0]]; // put your particular index where your image url in your array...
NSData *imgData = [[NSData alloc]initWithContentsOfURL:imgURL];
UIImage *img = [UIImage imageWithData: imgData];
[newView setBackgroundColor:[UIColor colorWithPatternImage:img]]

how to fetch image from array and show it on table view

I am fetching image from server and save it on a NSMutableArray. The result of array like that
myarray={"roger_50.jpg",....};
Now i dont know how to access this image on table view.
Just have proper URL for image in array. And pass it to NSURL object as a link.
NSURL *imageURL = [NSURL URLWithString:[myarray objectAtIndex : yourindex]];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:data];
Have a nice coding.
Stay Hungry, Stay Foolish...
i hope the thing you are getting from array are only the names you can retrieve images from server in only two ways i) in nsdata ii)by url of the images on sever .By this way you cann't access the images.

making UIImage from bytes

I have some data that is coming in xml tag from server and is in byte form
i have to convert it to UIImage
I have tried various links on google and also here but no help...
I have used
`NSData *fileData = [NSData dataWithBase64EncodedString:#"/qf20+EWOfpJfjrUaU6n1fSRjXF8ALQZEDy8v7az8Ks8/................SVrttqCV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.
Please help.
You can make use of
UIImage *image = [[UIImage alloc] initWithData:data];
or
UIImage *image = [UIImage imageWithData:data];
The data in the data parameter must be formatted to match the file format of one of the system’s supported image types.
Try the following (where data is of the NSData type):
UIImage *img = [[UIImage alloc] initWithData: data];

How to download an image from the web and display it in an UIImageView?

How to download an image from the web and display it in an UIImageView? For example, I have an URL like:
http://sstatic.net/so/apple-touch-icon.png
Would I need to mess around with NSURLConnection and the like, or is there a simple method that takes an web URL and downloads the image data automatically?
You can use NSData's dataWithContentsOfURL: class method to download the image data from the server, then just pass that data to UIImage's imageWithData:class method.
Here's an example:
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://sstatic.net/so/apple-touch-icon.png"]];
UIImage *downloadedImage = [UIImage imageWithData:imageData];
myImageView.image = downloadedImage;

To add UIImage directly to file

I want to add my UIImage directly into the file instead of converting into UIImagePNGRepresentation or UIImageJPGRepresentation(as it takes time) like:-
UIImage *im = [UIImage imageWithCGImage:ref];
[array addObject:im];
NSData *data = [array objectAtIndex:i];
[data writeToFile:path atomically:YES];
But it is showing error.
So there is any way that i can do it.
Thanks in Advance.
your use of the array only obfuscates that you are basically doing:
NSData *data = im;
Which cannot possibly work because im is a UIImage, and not an NSData nor a subclass.
What you want to do is to create a new NSData and initialize it with the content of the image. Since you got a CGImageRef, I suggest using it directly, without using a UIImage in between.
CGDataProviderRef imageDataProvider = CGImageGetDataProvider(ref);
CFDataRef imageData = CGDataProviderCopyData(imageDataProvider);
NSData *data = (NSData*) imageData;
Note that it is OK to cast the CFDataRef to NSData* because CFData is “toll-free bridged” with its Cocoa Foundation counterpart, NSData.
I hope that helps.
(don't forget to release data when done)