调整大小致使摄像机流 [英] Resizing Resulting Camera Stream

查看:164
本文介绍了调整大小致使摄像机流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户拍摄图像,并使用图像将其添加到屏幕上。不过,我也需要调整这一形象下降到约一半大小,由于内存限制(500万像素12倍的图像是从来没有很好的在手机上...)

I am trying to let a user capture an image and add it onto the screen using an Image. However, I also need to resize this image down to about half size due to memory restrictions (12x 5MP images is never good on a phone...)

我下水相机任务罚款,它调用已完成事件。然而,当我尝试使用DecodeJpeg我得到一个参数不正确。例外。

I am launching the camera task fine and it calls the Completed event. However, when I try and use DecodeJpeg I get a "The parameter is incorrect." exception.

下面是我的调整,代码,其中MX和我的尺寸是int类型。我已经验证,有一些在e.ChosenPhoto约5500〜的长度:

Here is my code for resizing, where mx and my are int for dimensions. I have verified that there is something in the e.ChosenPhoto with a length of about ~5500:

WriteableBitmap bitmap = PictureDecoder.DecodeJpeg(e.ChosenPhoto, mx, my);
Image img = new Image();
img.Source = bitmap;



第一行是那里的应用程序崩溃。任何想法

The first line is where the app crashes. Any ideas?

编辑:
这也会发生在PhotoChooserTask结果....

This also occurs with the result from the PhotoChooserTask....

推荐答案

尝试使用的 System.Windows.Media.Imaging - Extensions.LoadJpeg 方法代替的 PictureDecoder.DecodeJpeg 。另外,还要确保流被定位在流的开始。如果您已经使用的流,你需要使用重置:

Try using the System.Windows.Media.Imaging - Extensions.LoadJpeg method instead of PictureDecoder.DecodeJpeg. Also make sure that the stream is positioned at the beginning of the stream. If you have already used the stream you will need to reset it using:

MyImageStream.Seek(0, System.IO.SeekOrigin.Begin)

我有很多的努力来获得访问原始图像的问题,尤其是因为BitmapImage的超过2000×2000 自动调整图像。如果你想要一个形象大于2000x2000大,你必须访问原始的流,并将其加载到的 WriteableBitmap的对象

I had a lot of problems trying to get access to the original image, especially since BitmapImage automatically resizes images over 2000x2000. If you want an image larger than 2000x2000 you have to have access to the original stream and load it into a WriteableBitmap object

如果您希望看到一些更复杂的图像处理代码,包括检测来自图像分辨率流使用 ExifLib 并使用的 WriteableBitmap的扩展检查出的 BarcodeCaptureResult Silverlight的ZXing库类。

If you want to see some more complex image handling code including detecting resolution from image stream using ExifLib and rotating stream using the WriteableBitmap Extensions check out the BarcodeCaptureResult class for the Silverlight ZXing Library.

更新:由于所有你想要的是调整给出的e.ChosenPhoto结果我从Silverlight的ZXing库拉到代码的图像。这应该工作:

UPDATE: Since all you want is to resize an image given the e.ChosenPhoto result I pulled the code from The Silverlight ZXing library. This should work:

WriteableBitmap wbBarcodeImage = new WriteableBitmap(mx, my);
Extensions.LoadJpeg(wbBarcodeImage, e.ChosenPhoto);//Load JPEG from stream into our re-sized writeable bitmap

请注意,您将需要使用正确的高度/宽度的比例,否则就会在图像的底部或一侧的黑条。您可以使用ExifLib检测原始图像的大小,并用它来扩展(参见GetWriteableBitmap在BarcodeCaptureResult方法上面链接)

Note that you will need to use the correct height/width ratio, otherwise you will have a black bar at the bottom or side of the image. You can use ExifLib to detect the original image size and use that to scale (see GetWriteableBitmap method in BarcodeCaptureResult linked above)

这篇关于调整大小致使摄像机流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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