convert jpeg image into a byte array and byte array into a jpeg image

Discussion in 'iOS Programming' started by ranjimagi, Dec 21, 2009.

  1. ranjimagi macrumors newbie

    Nov 25, 2009
    I need to know is there is a way to convert a JPEG image to Byte array and byte array to JPEG image.I need to know how to do in iphone application.Thanks in advance.
  2. kainjow Moderator emeritus


    Jun 15, 2000
    To read an image from file you can use CGImageSourceCreateWithURL() which will give you CGImageRefs. You can get the image data via CGImageGetDataProvider(). If you need to convert to another data format, use a CGBitmapContext. UIImageJPEGRepresentation() can be used to get the JPEG data from a UIImage/CGImageRef.
  3. ranjimagi thread starter macrumors newbie

    Nov 25, 2009
    convert jpec image to byte array

    Thanks for your reply....

    At present we are reading an image from resource file.We r using the following code
    CGRect myImageRect = CGRectMake(0.0f, 0.0f, 300.0f, 250.0f);
    	UIImageView *imageview = [[UIImageView alloc] initWithFrame:myImageRect];
    	[imageview setImage:[UIImage imageNamed:@"image1.jpg"]];
    	imageview.opaque = YES; // explicitly opaque for performance
    	[self.view addSubview:imageview];
    Now we can display the image.But we want convert that image to Byte array.Then again convert Byte array to Image.Then finally to display that image.Actually i am new in iPhone developing.i tried.But i didn't get.i hope u will give better idea regarding this...


Share This Page