0

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.

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();
        }

    }
M_K
  • 3,247
  • 6
  • 30
  • 47

1 Answers1

0

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

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

apocalypse
  • 5,764
  • 9
  • 47
  • 95
  • I get Invalid cross-thread access when I try to save with `var bitmapImage = new BitmapImage(); bitmapImage.SetSource(e.ImageStream); WriteableBitmap wb = new WriteableBitmap(bitmapImage); IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); using (IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName)) { wb.SaveJpeg(myFileStream, 10, 10, 0, 70); }` – M_K Apr 15 '12 at 17:50
  • Like i said, i dont know anything about windows phone :P – apocalypse Apr 15 '12 at 20:39