简体   繁体   English

压缩后将可写位图转换为byte []数组的最佳方法?

[英]Best way to convert a writeable bitmap to byte[] array after compression?

I'm using a webcam to capture an image in silverlight. 我正在使用网络摄像头在Silverlight中捕获图像。 now i need to convert it into a byte[] array. 现在我需要将其转换为byte []数组。 Right now I use something like this: 现在我用这样的东西:

WriteableBitmap img = e.Result;
int[] p = img.Pixels;
int len = p.Length * 4;
byte[] result = new byte[len]; // ARGB
Buffer.BlockCopy(p, 0, result, 0, len);

However, the size of the resultant arrray is about 2MB which is rather large. 但是,产生的错误的大小约为2MB,这相当大。 What are my options for achieving better compression? 我有哪些选择可以实现更好的压缩效果? (right now I'm thinking of using some opensource compression code and reducing the size of the cam). (现在我正在考虑使用一些开源压缩代码并减小cam的大小)。

You can use the BitmapEncoder to encode your bitmap as jpeg or png. 您可以使用BitmapEncoder将位图编码为jpeg或png。

The docu has some example how to use it. 该文档有一些使用示例。 Don't know if this is available in silverlight though. 不知道这是否在Silverlight中可用。

Anyways it might be a good idea to use something like https://imagetools.codeplex.com/ because this library should work fine with silverlight and you don't have to struggle with issues getting your own implementation running... 无论如何,使用https://imagetools.codeplex.com/之类的东西可能是一个好主意,因为该库在Silverlight中应该可以正常工作,并且您不必为使自己的实现运行而烦恼...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM