[英]How to convert Image to Bitmap or Byte Array
I want to translate an Image into a MemoryStream or an array of bytes, but this does not work, I used to translate in Windows Forms in the same way as I did in Xamarin.Forms?我想把一个Image翻译成一个MemoryStream或者一个字节数组,但是这不起作用,我以前在Windows Forms中翻译的方式和我在Xamarin.Forms中的翻译方式一样吗?
MemoryStream ms = new MemoryStream();
img.Save(ms, img.Image.RawFormat);
byte[] byteimg = ms.ToArray();
Unlike Windows.Forms or WPF where the Image class has direct access to pixels and can provide the entirety of image manipulation APIs, Image class in Xamarin Forms is just an abstraction for multiple platform views across OSes (Android, iOS, macOS etc.) It provides limited capabilities when compared to any of the platform controls and basically is tasked with creating a platform view, loading picture from one of predefined sources (embedded resource, file, byte stream etc.), placing it somewhere in the visual tree. Unlike Windows.Forms or WPF where the Image class has direct access to pixels and can provide the entirety of image manipulation APIs, Image class in Xamarin Forms is just an abstraction for multiple platform views across OSes (Android, iOS, macOS etc.) It provides limited与任何平台控件相比的功能,主要任务是创建平台视图,从预定义源之一(嵌入式资源、文件、字节 stream 等)加载图片,将其放置在可视化树中的某个位置。 That's it, XF Image class is not tasked with low level pixel manipulation and doesn't provide access to the actual bit data of a native image.
就是这样,XF Image class 不负责低级像素操作,也不提供对原始图像的实际位数据的访问。 You won't find methods that give you access to pixel and as such don't allow you to create a Stream from a loaded into memory byte data.
你不会找到让你访问像素的方法,因此不允许你从加载到 memory 字节的数据中创建 Stream。
In order to get access to individual bytes you can:为了访问单个字节,您可以:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.