I'm using the following code from Three20 to display a photo/image gallery. Can anyone help with changing the code to display an image that's locally stored on the phone instead of on a web server?
[[[MockPhoto alloc]
initWithURL:#"http://farm4.static.flickr.com/3444/3223645618_13fe36887a_o.jpg"
smallURL:#"http://farm4.static.flickr.com/3444/3223645618_f5e2fa7fea_t.jpg"
size:CGSizeMake(320, 480)
caption:#"This is a caption."] autorelease],
you can make a data base table on which you store the image after been changed to an NSData object
Related
i'm sorry for my english.
i'm new in iphone development and happens to me a strange things.
I have a set of jpg images to show in a table view. When i test the app in iphone simulator everything is ok and work properly but when built and run the same code in iphone test device the same images aren't displayed.
Another strange behavior is that with a set of png images instead of jpg are shown perfectly in simulator like as in iphone test device.
Anyone can suggest me a solution?
I detect the name of image to load from a json file. This is the code that i use to show the image:
UIImageView *immaginePiadina = [[UIImageView alloc] initWithFrame:immagineValueRect];
[immaginePiadina setImage:[UIImage imageNamed:[item objectForKey:#"immagine"]]];
where [item objectForKey:#"immagine"] is an element of my json file like this:
"nome": "66",
"immagine": "pianetapiadabufalavesuviani",
"prezzo": "€ 7,50",
"nomeingrediente": [
"bufala",
"vesuviani"
]
How you can see i refer to the image with only the name of the file and without the file extension. I did it in this way to show image retina, it's wrong?
I exclude that i wrote a different case sensitive name because the png set works properly.
thanks a lot!!
There are possibly two separate issues that need separation, here is how to solve your problem.
First write a method using the NSFileManager, that given a file path verifies a file exists and has a size greater than 0. Insert a call to this everywhere you fail to open an image. If you use "imageNamed" then get the path to the bundle and create the path. If this method fails to find an image, fix it.
Second, the image decoding is different for the simulator and the device - the simulator uses the full OSX libraries. So take one image that fails to open and move it somewhere. Open it in Preview and export it using the same name but with png+alpha format. Change your code to expect a png not a jpg, and retest. Make sure you still use the first method to insure the file is there.
Once you get one success you can try other options, like using Preview exported jpegs. The reason this should work is that all of these image formats permit a huge range of options all of which iOS does not support.
Given that the current format us the problem, you can script changes using the "sips" program, which is what Preview uses.
I solve my problem using the following code:
NSString* path = [[NSBundle mainBundle] pathForResource:[item objectForKey:#"immagine"] ofType:#"jpg"];
NSLog(#"%#",path);
UIImage* theImage = [[UIImage alloc] initWithContentsOfFile:path];
I don't know the reason but in this way i haven't any problem to display jpg in my iPhone test device. Maybe because NSBundle specify also the extension of the file.
Thanks #David-h that directed me in the right way to solve my problem.
Check the extensions of your images. If you write .PNG, in the simulator is Ok, but not in the device.
I am making a small application where I am receiving images from web-service. I am getting the image url. And the format of images is different different like .jpg,.gif,.png etc. And I want to save these images into my sandbox and later on show it into image view.
To do this I am giving a self name and gave the extension to .png. But at the time of retrieving the .png images are shown but different one's are not shown. So can you give me any idea how to convert all images to .png format or any other approach to do this?
after you retrieve your images/url save them this way:
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
Would it not be easier if you use an image library like SDWebImage which handles all the asynchronous image downloading and caching of the image onto your device?
https://github.com/rs/SDWebImage
Then you can do something like:
[myImageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
I'm writing a function to download a regular PNG file from web server and save it to iPhone Photos album. I don't get any error for my code listed below but UIImagePNGRepresentation doesn't perform the convert at all. All images I got were black. I have to enable "auto-enhanced" under Photos to display those image properly. Any clue what's wrong with my code? Thanks in advance.
UIImage *orgImg = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://server.com/test.png"]]];
NSData * convertedData = UIImagePNGRepresentation(orgImg);
UIImage * img = [UIImage imageWithData: convertedData];
// Save Image to Photo Album
UIImageWriteToSavedPhotosAlbum(img, self,
#selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), nil);
Some more details of these two output images, orgImg and img:
If I pass orgImg to UIImageWriteToSavedPhotosAlbum directly, I did get the same PNG image hosted on the server. However Photos application on my iPhone displays it as a black image because Photos doesn't enhance PNG format automatically.
As for the img I got after using UIImagePNGRepresentation, the image data has been changed by the method, some meta data such as width/height have been removed from the original image. However Photos app on my iPhone still display it as an all black image.
Both images display properly if I copy them into either Safari or email. I didn't get any problem if I use JPEG in the server side either. Just curious why only PNG format doesn't work.
We have images stored in our SQL Server db in an image type field. Im just wanting to know how I go about getting them into a UIImageView in my iPad app. My iPad app talks to the SQL Server over an OData service provider so the image field comes across as type NSData so I tried the following code already:
UIImage *currentImage = [[UIImage alloc] initWithData:[currentEntityImage getEntityImageData]];
[myImageView setImage:currentImage];
Where "[currentEntityImage getEntityImageData]" is the NSData field converted from the image field. The problem is I can never get anything to display in the UIImageView.
Here is the corresponding code I use in our .net application that shows the image correctly:
Dim EntImage As EntityImage = CType(e.Entities.Item(0), EntityImage)
Dim ms As New System.IO.MemoryStream(EntImage.EntityImage)
Me.imgEntityImage.Image = System.Drawing.Image.FromStream(ms)
This works fine and shows the image correctly (i am accessing the same data on both platforms).
Any ideas on what im missing in my obj-c code? Ive been pulling my hair out all morning on this.
Thanks in advance
maybe the data returned from OData is encoded Base64.
Try decoding it with http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
Hope it helps
Try this
NSData *imageData =[NSData dataWithData:[currentEntityImage getEntityImageData]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData];
[myImageView setImage:animalImage];
Hi i want to upload the image to HTTP server, image upload is working fine but every time the image in the server is replaced with the new image. Can some one help me to implement the commented lines below.
Thanks...
- (IBAction)upload{
//NSString *imagename=imageview.image;
//[self uploadImage:UIImageJPEGRepresentation(imageview.image, 1.0) filename:imagename];
[self uploadImage:UIImageJPEGRepresentation(imageview.image, 1.0) filename:#"facebook.jpg"];
}
To get the image's filename, capture the name during the file picking (but remember, maybe the image in the image view comes directly from the camera).
If the file upload should never overwrite a file already on the server, consider one of the following:
a) generate a unique filename for each upload (preferably in the server code, but if you also control the client, you can do it there too). You could use UUIDs as unique filenames.
OR
b) store the images in a database instead of the filesystem