Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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 method needs a stride parameter, which I don't know how to obtain. As far as I know, stride is value that's used when stepping in the array during reading or copying. What would be an appropriate stride value for any BitmapSource?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...