【问题标题】:Conversion of RLE to UIImageView.Image in IOSIOS中RLE到UIImageView.Image的转换
【发布时间】:2012-06-12 05:41:23
【问题描述】:

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

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

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

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

如何使 _data 格式与 UIImage 兼容

【问题讨论】:

  • 您需要手动对其进行解码并将其转换为支持的格式。 RLE 是一种通用技术,而不是具体的图像格式。您可以使用任何类型的图像查看器查看此图像数据吗?如果可以,那么您应该能够确定它的实际格式,这将帮助您弄清楚如何转换它。

标签: mono xamarin.ios monodevelop


【解决方案1】:

在实现 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    相关资源
    最近更新 更多