喜欢标题。如何在都市风格的应用程序中将BitmapeImage转换为byte。 Ther不是System.drawing lib。 我需要它在LuminanaceSource()中使用,它需要byte []中的source。 有一些例子,但我不知道如何使用它。
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
var encoderId = Windows.Graphics.Imaging.BitmapEncoder.JpegEncoderId;
由于
答案 0 :(得分:0)
这两种方法应该将Bitmap图像转换为byte [],反之亦然。
public BitmapImage ImageFromBuffer(Byte[] bytes)
{
MemoryStream stream = new MemoryStream(bytes);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
return image;
}
public Byte[] BufferFromImage(BitmapImage imageSource)
{
Stream stream = imageSource.StreamSource;
Byte[] buffer = null;
if (stream != null && stream.Length > 0)
{
using (BinaryReader br = new BinaryReader(stream))
{
buffer = br.ReadBytes((Int32)stream.Length);
}
}
return buffer;
}