如何减少Windows手机中的图像大小

我想在Windows手机中移植我的应用程序。 我必须在服务器上传一个图像所以它是小尺寸上传我已经在Widows成功完成了这件事但问题是当我失败了..这里是我的代码为Windows App

public void CompressImage(int i, int j) { bmp1.SetPixel(j, i, Color.FromArgb(bmp.GetPixel(j, i).R, bmp.GetPixel(j, i).G, bmp.GetPixel(j, i).B)); } private void bLoadImage_Click(object sender, EventArgs e) { OpenFileDialog file = new OpenFileDialog(); if (file.ShowDialog() == DialogResult.OK) { pictureBox1.Image = new Bitmap(file.FileName); } } private void bCompression_Click(object sender, EventArgs e) { bmp = new Bitmap(pictureBox1.Image); bmp1 = new Bitmap(bmp.Width, bmp.Height); for (int i = 1; i < bmp.Height; i++) for (int j = 1; j < bmp.Width; j++) { CompressImage(i, j); } pictureBox2.Image = bmp1; bmp1.Save("Picture.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); } 

在谷歌搜索后我发现Windows Phone不支持Bitmap ..任何想法我如何在Windows手机或任何其他替代方案做同样的事情

您应该使用WriteablBitmap来减小图像的大小。 WriteablBitmap在windows phone中有多种图像方法这里有更多关于writeablebitmapex的信息。

尝试将原始图像加载到WriteableBitmap对象,然后可以使用System.Windows.Media.Imaging命名空间中的SaveJpeg()扩展方法来保存缩小大小的新图像。 例如 :

 ....... WriteableBitmap wb = new WriteableBitmap(bitmapImageObject); wb.SaveJpeg(stream, 120, 160, 0, 100); ....... 

拍照时,您可以选择拍摄照片的分辨率。 这可以通过

 PhotoCamera cam; 

相机启动后。

捕获图像时的代码(在捕获图像的方法中)

 IEnumerable resList = cam.AvailableResolutions; Size res; if (resList.Count() > 0) { res = resList.ElementAt(0); cam.Resolution = res; } 

此示例选择第一个分辨率

你可以试试这个。 它对我有用。 它将我的9.70MB文件减少到270KB。

 WriteableBitmap cameraCapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto, 1024, 1024); using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName)) { System.Windows.Media.Imaging.Extensions.SaveJpeg(cameraCapturedImage, myFileStream, cameraCapturedImage.PixelWidth, cameraCapturedImage.PixelHeight, 0, 85); myFileStream.Close(); } 

注意:fileName是保存大小缩小图像的文件名。