BitmapSource.CopyPixels -what's a good value for stride?

前端 未结 2 1499
面向向阳花
面向向阳花 2020-12-15 23:43

I\'m trying to get the pixel data from a WPF BitmapSource object. As I understand, this can be accomplished by calling its CopyPixels method. This

相关标签:
2条回答
  • 2020-12-16 00:12
    var stride = ((bitmapSource.PixelWidth * bitmapSource.Format.BitsPerPixel + 31) / 32) * 4;
    

    or

    var stride = ((bitmapSource.PixelWidth * bitmapSource.Format.BitsPerPixel + 31) >> 5) << 2;
    
    0 讨论(0)
  • 2020-12-16 00:15

    You can use stride = pixel_size * image_width value. For example, for RGBA bitmap with 100 pixel width, stride = 400.

    Some applications may require special line alignment. For example, Windows GDI bitmaps require 32-bits line alignment. In this case, for RGB bitmap with width = 33, stride value 33*3=99 should be changed to 100, to have 32-bits line alignment in destination array.

    Generally, you should know destination array requirements. In there are no special requirements, use default pixel_size * image_width.

    0 讨论(0)
提交回复
热议问题