0

如何将 RLE 图像数据转换为 IOS 兼容的图像格式(IOS 支持)

ImgView.Image = UIImage.LoadFromData(_data) // _data contains of size 1350124

_data 包含 RLE 格式的图像字节数组。而分配给 ImgView.Image 它得到

空值。所以图像不会显示在 UIImageView 上。

如何使 _data 格式与 UIImage 兼容

4

1 回答 1

2

在实现 RLE 算法之后,我只在几行代码下面进行了长时间的斗争,最后我得到了解决方案

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);
于 2012-06-13T13:24:09.297 回答