在iOS中将RLE转换为UIImageView.Image [英] Conversion of RLE to UIImageView.Image in IOS

查看:60
本文介绍了在iOS中将RLE转换为UIImageView.Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How I can convert RLE image data to IOS compatible image format (that is supported by IOS)

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

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

_data contains the byte array of image in RLE format. while is assign to ImgView.Image it gets

为空.因此图像不会显示在UIImageView上.

null. so image is not display on UIImageView.

如何使用UIImage使_data兼容格式

how to make _data compatible format with UIImage

推荐答案

在实现RLE算法后,我只在下面几行代码中编写了很长时间,最后我找到了解决方案

after implementing RLE Algorithm just i code below few line of code long struggle finally I got it solution

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);

这篇关于在iOS中将RLE转换为UIImageView.Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆