How to insert image in xml on iphone - iphone

In my app i insert images in the tableview by putting the url of image in the field image of xml!!
It's possible insert the entire image directly in XML, including in the field image, instead of the URL, a kind of image compression, for example, the bits that make up the image.

This will increase the loading time a lot!
Search for a solution for "lazy loading" on the Web.
This is the most common approach for loading images in the table views on iPhone...
EDIT:
If you still want to use blub (image data as text inside the XML) then you might use the next code sample:
NSData *imageData = [NSData dataWithBase64EncodedString:imageString];
UIImage *image = [UIImage imageWithData:imageData];

Related

How to convert all image format into .png format?

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"]];

Unable to convert a PNG image using UIImagePNGRepresentation

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.

Load image from a stored png

How does one load or fetch an image that was saved to disk?
I wrote the image to the documents filepath using NSData and a PNG representation. How does one get this image back? UIImage.
UIImage *theImage = [UIImage imageWithContentsOfFile:filePath];
As ever, see the UIImage documentation at Apple. It is your friend.

Loading Image from SQL Server DB Image Field into UIImageView

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];

No thumbnail in iPhoto for images saved with UIImageWriteToSavedPhotosAlbum

My application downloads JPEG images from the web and save them to the device using UIImageWriteToSavedPhotosAlbum. All works fine except for one issue: when I browse iPhone's photo library with iPhoto, some images have no thumbnails -- an empty dashed rectangle is displayed instead. Those JPEG images application downloads are also generated by my application as a result of processing pictures either taken by device camera or picked from Photo Library. Maybe I need to do something special during image processing that will make thumbnails visible?
Try something like
UIImage * original = [UIImage imageNamed:#"sample.jpg"]; /* make image from CGRef */
NSData * imdata = UIImagePNGRepresentation ( original ); /* get PNG representation */
UIImage * png = [UIImage imageWithData:imdata]; /* wrap UIImage around PNG representation */
UIImageWriteToSavedPhotosAlbum(png,
self,
#selector(image:didFinishSavingWithError:contextInfo:),
nil);
This will convert your image to PNG, and the thumbnail will show in Photos.app.