none
BitmapSource.Create error RRS feed

  • Question

  • I am trying to use BitmapSource.Create and it is throwing an argumentException saying that the value does not fall withint the expected range. The problem is that it doesn't say what the value is or anything. Here is my code of when I call Create

     

    Code Snippet

    _stride = _width /PixelFormats.Bgr32.BitsPerPixel;

    BitmapSource bitmap = BitmapSource.Create(_width, _height, _dpiX, _dpiY, PixelFormats.Bgr32, null, _byteArray, _stride);

     

     

    And here is the StackTrace in case that can help.

     

       at MS.Internal.HRESULT.Check(Int32 hr)
       at System.Windows.Media.Imaging.CachedBitmap.InitFromMemoryPtr(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette, IntPtr buffer, Int32 bufferSize, Int32 stride)
       at System.Windows.Media.Imaging.CachedBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette, Array pixels, Int32 stride)
       at System.Windows.Media.Imaging.BitmapSource.Create(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat, BitmapPalette palette, Array pixels, Int32 stride)
       at Reporting.XAML.EmbeddedImage.ProvideValue(IServiceProvider serviceProvider) in C:\source\New support\Reporting\PrintGroupExtension.cs:line 148
       at System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension(MarkupExtension markupExtension, Object obj, Object member)
       at System.Windows.Markup.BamlRecordReader.SetDependencyComplexProperty(Object currentTarget, BamlAttributeInfoRecord attribInfo, Object o)

     

    Any help is appreciated.

    Thanks,

    David

    Tuesday, August 7, 2007 6:20 PM

Answers

  • I found my problem and will explain in case anybody else comes to this, you see my byte[] started out as a memory stream so BitmapSource.Create was not the correct approach. Instead I can use a BitmapImage, do a beginInit() and set the StreamSource of the bitmap to be a new memorystream created from my byte[]. No more PixelFormats or strides

     

    Tuesday, August 7, 2007 9:37 PM