简体   繁体   English

如何缩小图像尺寸

[英]How can I reduce the size of an image

I am trying to reduce the size of an Image I am taking from the camera before I save it to Isolated Storage. 我试图减小从相机拍摄的图像的大小,然后再将其保存到隔离存储中。 I already have it reduced to the lowest resolution (640x480) How can I reduce the bytes to 100kb instead of what they are coming out at almost 1mb. 我已经将其降低到最低分辨率(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();
        }

    }

I have nothing about Windows Phone, but maybe this link will help you: http://msdn.microsoft.com/en-us/library/ff769549(v=vs.92).aspx 我对Windows Phone毫无了解,但也许此链接可以为您提供帮助: http : //msdn.microsoft.com/zh-cn/library/ff769549(v=vs.92).aspx

1) load your jpeg 2) copy to bitmap 3) save as bitmap with quality settings http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.extensions.savejpeg(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM