0

I am having file with extension .RGB and need to display it on uiimageview.

For this i need to convert the .RGB format to specific format like .PNG or .JPEG however unable to get it right . I tried with following code for this.

    UIImage *image=[UIImage imageNamed:@"Attachment.RGB"];
CGImageRef imageRef=[image CGImage];
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
NSData *pngData = UIImagePNGRepresentation(myImage);
UIImage* imageFinal = [UIImage imageWithData:pngData];

image_view.image=imageFinal;

There are online websites which can convert the RGB to visible image .But i didn't found any solution for objective c . Can any one help me on this .

Regards Pagyyy123

user968597
  • 1,164
  • 2
  • 15
  • 30

1 Answers1

1

You can use the readtex.c for this which is open source implementations for this.. see the sample following code snippets...

static TK_RGBImageRec *tkRGBImageLoad(const char *fileName)
{
   rawImageRec *raw;
   TK_RGBImageRec *final;

   raw = RawImageOpen(fileName);
   if (!raw) {
      fprintf(stderr, "File not found\n");
      return NULL;
   }
   final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec));
   if (final == NULL) {
      fprintf(stderr, "Out of memory!\n");
      return NULL;
   }
   final->sizeX = raw->sizeX;
   final->sizeY = raw->sizeY;
   final->components = raw->sizeZ;
   RawImageGetData(raw, final);
   RawImageClose(raw);
   return final;
}

http://opensource.apple.com/source/X11server/X11server-85/mesa/Mesa-7.2/progs/util/readtex.c

I hope the above URL will help.

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45