如何将RLE图像数据转换为IOS兼容图像格式(IOS支持)
ImgView.Image = UIImage.LoadFromData(_data) // _data contains of size 1350124
_data包含RLE格式的图像字节数组。虽然分配给ImgView.Image,但它得到了
空。所以图像不会显示在UIImageView上。
如何使用UIImage制作_data兼容格式
答案 0 :(得分:2)
Byte _imgData = GetRawData(_imgPath); // this method get the byte array of size ([131072])
NSData _data = NSData.FromArray(_imgData);
ImgView.Image = UIImage.LoadFromData(_data)
int rawWidth = PixelData.ImageWidth;
int rawHeight = PixelData.ImageHeight;
float[] _rawSize = new float[rawWidth * rawHeight * 4];
for (int i =0; i < rawWidth * rawHeight; ++i) {
_rawSize [4 * i] = (float)(1.0 / 255.0);
_rawSize [4 * i + 1] = (float)(1.0 / 255.0);
_rawSize [4 * i + 2] = (float)(1.0 / 255.0);
_rawSize [4 * i + 3] = 255;
}
int bitsPerComponant = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * rawWidth;
CGDataProvider _provider = new CGDataProvider (_imgData, 0, _imgData.Length);
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
CGImage cg = new CGImage (
rawWidth,
rawHeight,
bitsPerComponant,
bitsPerPixel,
bytesPerRow,
colorSpace,
CGBitmapFlags.ByteOrderDefault,
_provider,
null,
true,
CGColorRenderingIntent.Default
);
ImgView.Image = UIImage.FromImage (cg);