转换的UIImage到字节数组 [英] Converting UIImage to Byte Array

查看:400
本文介绍了转换的UIImage到字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个UIImage转换为字节数组。我使用Xamarin的Visual Studio插件产生iOS应用程序。



下面的代码位获取的图像,但我需要跨越服务栈将其作为一个字节数组,而不是一个UIImage。

  VAR signatureView =新SignaturePad.SignaturePadView(新的RectangleF(10,660,300,150)); 
signatureView.BackgroundColor = UIColor.White;
this.View.AddSubview(signatureView);
的UIImage signatureImage = signatureView.GetImage();


解决方案

无耻地从的ChrisNTR

 使用(NSData的为imageData = image.AsPNG()){
字节[] = myByteArray新的字节[imageData.Length]
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes,myByteArray,0,Convert.ToInt32(imageData.Length));
}


I need to convert a UIImage to a byte array. I am using Xamarin's Visual Studio plugin to produce an iOS application.

The bit of code below gets the image, but I need to send it across a Service Stack as a byte array instead of a UIImage.

        var signatureView = new SignaturePad.SignaturePadView(new RectangleF(10, 660, 300, 150));
        signatureView.BackgroundColor = UIColor.White;
        this.View.AddSubview(signatureView);
        UIImage signatureImage = signatureView.GetImage();

解决方案

Shamelessly stolen from ChrisNTR

using (NSData imageData = image.AsPNG()) {
  Byte[] myByteArray = new Byte[imageData.Length];
  System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
}

这篇关于转换的UIImage到字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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