I have function in wcf json service take two parameters to upload an image:
Public Function UploadDamageImage(ByVal UploadDamageImageRequest As UploadDamageImageRequest) As UploadDamageImageResponse
How can I send an image as a parameter to this function as bytes?
I'm using AFHTTPRequestOperationManager.
To send a UIImage as bytes to a function, you can first convert the UIImage to a NSData object and then get the byte array from that.
UIImage *image = // your image...
NSData *imgData = UIImagePNGRepresentation(image);
NSString *byteArr = [data base64Encoding];
For the second line of code, the Apple Docs for UIImage explains:
...you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.
Related
I don't want to use NSUserDefaults, so how do I save an image in core data then retrieve it?
My image is in this variable.
var image:UIIMage = image1
Can you please give me some sample code to do this?
UIImage -> NSData
NSData *imageData = UIImagePNGRepresentation(image); or UIImageJpegRepresentation(image)
NSData -> UIImage
UIImage *image=[UIImage imageWithData:data];
Convert UIImage into NSData and save as the entity's attribute with the type Binary Data
this question is already answered by stack-overflow refer this
How to store an image in core data
I am writing NSData to a file and saving it in the device's app documents folder. For that, is it possible to get thumbnail from ALAssetsRepresentation object in NSData format. If so, any helpful links to that?
I couldn't find anything similar, other than getting CGImageRef from ALAssetsRepresentation. I don't want CGImageRef format as I have to use UIImageJPEGRepresentation or UIImagePNGRepresentation to convert it to NSData.
Try this one
GImageRef iref = [myasset thumbnail];
if (iref)
{
UIImage *theThumbnail = [UIImage imageWithCGImage:iref];
NSData *thumnailData = UIImagePNGRepresentation(theThumbnail);
}
I'm trying to display a BLOB image (get from web server using Json) in my iOS app, but when I run my application I get an empty UIimageView, here is my code :
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:encodedUrl]];
NSData *profileImage1 = [[NSData alloc] initWithBytes:[dataURL bytes] length:[dataURL length]];
UIImage *profileImage2 = [UIImage imageWithData:profileImage1];
[profilImage setImage:profileImage2];
How can I fix this problem?
[UIImage imageWithData:data] only parses known image file formats like JPEG, PNG, etc. (Full info in the decomentation). Passing blobs isn't supported by UIImage. You need to do some decoding to be able to use the data for the UIImage. You can use GMTBase.64 for encoding and decoding of data. Read the docs and other posts and you'll find out how to change your code.
Hope this helps.
In my project i need to show the different sizes of images in zig-zag fashion. so, i converted the uiimages(url) which are coming from service to NSData and then i get the uiimage. my code is
NSURL *url = [NSURL URLWithString:[[_result objectAtIndex:i ] valueForKey:#"PImage"]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
so i can get the image size(width and height), But my problem is according to the image size, i need to create UIView, this code is works fine for me, but it is taking too much of time(almost 25 sec) to load 8 images. i figured converting UIImage to NSData is taking time. Is there any way to get the image size(width and height) without converting it into NSData
Thanks for spending time for me.
You can get image properties without actually loading whole image data from disk using ImageIO framework:
#import ImageIO;
...
NSURL *imageURL = … // Init URL somehow
CGImageSourceRef imgSource = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL);
NSDictionary* imageProps = (__bridge_transfer NSDictionary*) CGImageSourceCopyPropertiesAtIndex(imgSource, 0, NULL);
NSLog(#"%#", imageProps);
CFRelease(imgSource);
Image width and height will be stored in dictionary under PixelHeight and PixelWidth keys (tested with png image, may be other image formats will use different keys)
Instead of converting url to data and to UIImage, Use EGOImageView OR AsyncImageView. You can simply pass the URL to them. Again setFrame based on size of the image.
I want to send UIImage from my application to the server. I use ASIHTTPRequest. I'll send NSData but how to convert from UIImage to NSData?
If you need PNG data in your NSData you can use:
NSData *data = UIImagePNGRepresentation(img);
Where img is your UIImage. There is a similar function for JPG.
The UIKit functions UIImageJPEGRepresentation() and UIImagePNGRepresentation() should do what you want.