[英]How can I reduce the size of an image
我試圖減小從相機拍攝的圖像的大小,然后再將其保存到隔離存儲中。 我已經將其降低到最低分辨率(640x480)。如何將字節減少到100kb,而不是將近1mb的字節輸出。
void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
{
string fileName = folderName+"\\MyImage" + savedCounter + ".jpg";
try
{
// Set the position of the stream back to start
e.ImageStream.Seek(0, SeekOrigin.Begin);
// Save picture as JPEG to isolated storage.
using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
{
// Initialize the buffer for 4KB disk pages.
byte[] readBuffer = new byte[4096];
int bytesRead = -1;
// Copy the image to isolated storage.
while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
{
targetStream.Write(readBuffer, 0, bytesRead);
}
}
}
}
finally
{
// Close image stream
e.ImageStream.Close();
}
}
我對Windows Phone毫無了解,但也許此鏈接可以為您提供幫助: http : //msdn.microsoft.com/zh-cn/library/ff769549(v=vs.92).aspx
1)加載jpeg 2)復制到位圖3)使用質量設置另存為位圖http://msdn.microsoft.com/zh-cn/library/system.windows.media.imaging.extensions.savejpeg(v=vs。 92).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.