none
BitmapSource - CopyPixels : "The parameter value cannot be less" RRS feed

  • Question

  • Hi,

    I use the following method to copy a small icon :

    BitmapSource bms = (BitmapSource)Source;
    _original = new byte[bufferSize];
    int bufferSize = (int)(Width * Height * 4);

    bms.CopyPixels(_original, (int)(Width * 4), 0);

    But I got the following error :

    "The parameter value cannot be less" "128"

    Sometimes it is another value than 128 !

    The context :
    - It is the stride parameter !
    - I have this error with "some" pictures, not all pictures !
    - If I increase the stride parameter, I have the same proble with the size of the buffer. It tell me that
    the min size is 1024, but my image is 12x12 (It is an icon).

    Does someone has an idea to fix this ?

    Thx
    Tuesday, April 1, 2008 8:12 AM

Answers

  • You should give the correct stride value, you can use the following method to calculate the correct stride value:

    Int32 stride = (bms.PixelWidth * bms.Format.BitsPerPixel + 7) / 8;

    Hope this helps
    Thursday, April 3, 2008 2:45 AM

All replies

  • You should give the correct stride value, you can use the following method to calculate the correct stride value:

    Int32 stride = (bms.PixelWidth * bms.Format.BitsPerPixel + 7) / 8;

    Hope this helps
    Thursday, April 3, 2008 2:45 AM
  • I am having the same issue loading a single page 2color TIFF with 34 megapixels (4891x7022 pixels), and I have the correct stride formula.

    When I call CopyPixels, I get the ArgumentOutOfRangeException error "The parameter value cannot be less than 4297464".       (This number is <1% larger than 7022x4891/8)

    The code works when I take a small image, but not the large image.

     

      Dim uri As New ri("C:\temp\00000001.TIF", UriKind.Absolute)
      Dim tiffdecoder As New TiffBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
      Dim bmSource As BitmapSource
      bmSource = tiffdecoder.Frames(0)
      Dim stride As Int32 = CType((bmSource.PixelWidth * bmSource.Format.BitsPerPixel + 7) / 8,Int32)
      Dim pixels() As Byte
      ReDim pixels(bmSource.Height * stride)  ' this has value of 687595 for my image
      bmSource.CopyPixels(pixels, stride, 0)
    

     

    Monday, February 14, 2011 7:47 PM
  • Hi David, have you made any progress on this issue?

     

    -L

    Wednesday, February 16, 2011 5:36 PM