0

我正在尝试减小从相机拍摄的图像的大小,然后再将其保存到独立存储中。我已经将它降低到最低分辨率 (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();
        }

    }
4

1 回答 1

0

我对 Windows Phone 一无所知,但也许这个链接会对你有所帮助:http: //msdn.microsoft.com/en-us/library/ff769549 (v=vs.92).aspx

1) 加载您的 jpeg 2) 复制到位图 3) 保存为具有质量设置的位图 http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.extensions.savejpeg(v=vs. 92).aspx

于 2012-04-15T17:04:27.220 回答