本文介绍了将图像保存到Windows Phone 7中的本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我正在尝试将我的图像保存到本地数据库。图像由手机摄像头捕获(capture.show())。我正在尝试使用以下代码将图像转换为字节数组:



Hey guys, I am trying to save my image to the local database. the image is captured by the phone camera (capture.show()). I am trying to convert images to byte array using the code below:

public byte[] convertToByte(BitmapImage img)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                WriteableBitmap btmap = new WriteableBitmap(img.PixelWidth, img.PixelHeight);
                Extensions.SaveJpeg(btmap, ms, img.PixelWidth, img.PixelHeight, 0, 100);
                ms.Seek(0, SeekOrigin.Begin);
                return ms.ToArray();
            };
        }





我无法将图像传递给此方法,因为显示此图片的控件属于



I cant pass the image to this method as the control that displays this picture is of type

System.Windows.Controls.Image

并且上面的方法接受Bitmapimage对象。



如何修改我的代码?

and the above method accepts Bitmapimage object.

How do can i modify my code?

推荐答案

<pre>public byte[] convertToByte(Image imgControl)
{
  if(img.Source!=null)
  {
   BitmapImage img = img.Source as bitmapImage;
            using (MemoryStream ms = new MemoryStream())
            {
                WriteableBitmap btmap = new WriteableBitmap(img.PixelWidth, img.PixelHeight);
                Extensions.SaveJpeg(btmap, ms, img.PixelWidth, img.PixelHeight, 0, 100);
                ms.Seek(0, SeekOrigin.Begin);
                return ms.ToArray();
            };
   }
}


这篇关于将图像保存到Windows Phone 7中的本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:45