如何在uiimageview上显示RGB



我有一个扩展名为.RGB的文件,需要在uiimageview上显示它。

为此,我需要将RGB格式转换为特定的格式,如.PNG或JPEG,但无法正确处理。我为此尝试了以下代码。

    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;

有一些在线网站可以将RGB转换为可见图像。但我没有找到任何目标c的解决方案。有人能帮我吗。

问候Payyy123

您可以为此使用readtex.c,这是为此的开源实现。。请参阅以下代码片段的示例。。。

static TK_RGBImageRec *tkRGBImageLoad(const char *fileName)
{
   rawImageRec *raw;
   TK_RGBImageRec *final;
   raw = RawImageOpen(fileName);
   if (!raw) {
      fprintf(stderr, "File not foundn");
      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

我希望上面的网址会有所帮助。

最新更新