将 UIImage 转换为字节数组 [英] Converting UIImage to Byte Array

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

问题描述

我需要将 UIImage 转换为字节数组.我正在使用 Xamarin 的 Visual Studio 插件来生成 iOS 应用程序.

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

下面的代码获取图像,但我需要将它作为字节数组而不是 UIImage 发送到服务堆栈.

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

推荐答案

无耻地从 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天全站免登陆