sudeep gusain

sudeep gusain

  • NA
  • 3
  • 1.8k

Error creating BitmapSource object

Jul 31 2013 10:05 AM
When we are we are ceating a BitmapSource from an image file. Th code is working on my local system but mot on the staging and live.

It is working under Windows 7 (my local) and not under windows server 2008R2(live and staging). Most of the images having error are color representation as  "uncalibrated"

While decoding the file we are getting and error.

at System.Windows.Media.Imaging.BitmapFrameDecode.get_ColorContexts() at System.Windows.Media.Imaging.BitmapSource.CreateCachedBitmap(BitmapFrame frame, BitmapSourceSafeMILHandle wicSource, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, BitmapPalette palette) at System.Windows.Media.Imaging.BitmapFrameDecode.FinalizeCreation() at System.Windows.Media.Imaging.BitmapFrameDecode..ctor(Int32 frameNumber, BitmapSourceSafeMILHandle sourceHandle, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, BitmapDecoder decoder) at System.Windows.Media.Imaging.BitmapDecoder.SetupFrames(BitmapDecoder decoder, ReadOnlyCollection`1 frames) at System.Windows.Media.Imaging.BitmapDecoder.get_Frames() at DA.Image.CreateBitmap(String filePath) at DigitisedArt.Image.Create(Int32 accountID, Int32 imageID, Int32 batchID, Int32 assetID, Int32 userID, String guid, String filename, String notes)

I am using the following code to create BitmapSource.

BitmapDecoder decoder = null;
string fileExtension = Path.GetExtension(filePath).ToLower();
FileStream fileStream = new FileStream( filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
decoder = JpegBitmapDecoder.Create(fileStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
fileStream.Close();
(BitmapSource)decoder.Frames[0];


Kindly let us know where we are going wrong.

Answers (2)