Save to BMP

Aug 5, 2012 at 2:22 PM

Hi! How can I save an image to BMP format by Image Tools?

Thank you for your reply

Aug 8, 2012 at 9:40 AM


this tutorial shows how to save an Image. you Can use the BMPEncoder:

Aug 8, 2012 at 2:32 PM
Edited Aug 8, 2012 at 2:44 PM

I use Windows Phone
I'm using this code to save an Image:

void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
string fileName = "0.bmp";


ExtendedImage extendedImage = new ExtendedImage();
IImageEncoder encoder = new BmpEncoder();
MemoryStream memStream = new MemoryStream();
encoder.Encode(extendedImage, memStream);
memStream.Seek(0, SeekOrigin.Begin);//error: Cannot access a closed Stream

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 = memStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
targetStream.Write(readBuffer, 0, bytesRead);


 And at a runtime I get an error "Cannot access a closed Stream"

Aug 8, 2012 at 2:43 PM

when I use PngEncoder instead BmpEncoder the saving operation works well

but the loading operation is fall

I use this code to load a png  image:


private void button1_Click(object sender, RoutedEventArgs e)
BitmapImage bi = new BitmapImage();
IImageDecoder decoder = new BmpDecoder();
ExtendedImage ei = new ExtendedImage();

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("0.bmp", FileMode.Open, FileAccess.Read))
decoder.Decode(ei, fileStream);
 bi.SetSource(ei.ToStream());//error: not a valid index into buffer
image1.Source = bi;


I get an error:  "not a valid index into buffer", and "ei" is 0x0

Aug 8, 2012 at 5:26 PM
Edited Aug 8, 2012 at 5:27 PM

an object of the ExtendedImage class always null

If I assign a stream to this: extendedImage.setSource(memoryStream);

or I assign a file path to UriSource property: extendedImage.UriSource = new Uri("0.bmp", UriKind.Relative);

but a result is the same: ExtendedImage instance is null

Aug 9, 2012 at 1:46 PM

I attach events: "extendedImage_LoadingFailed" and "extendedImage_LoadingCompleted" to loading an image operation of the ExtendedImage instance, but this invoke "extendedImage_LoadingFailed" everytime

Does anybody know why this happen?


Jul 18, 2013 at 2:47 AM
Hi, this is the saving to BMP image online tutorial of the image converter tool which Im using now, by the way, which image or document formt do you want to save to bmp? cause image to BMP is different from document to BMP image.
Oct 10, 2013 at 3:41 AM
Bitmap is standard image file format for storing 2D digital images of arbitrary width, height, and resolution mainly used on Microsoft Windows operating systems. For some user, here is a powerful solution for viewing, editing, converting, annotating, saving and printing bitmap with a .NET Imaging SDK.