本文介绍了BitmapSource.CopyPixels - 步幅有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从WPF BitmapSource 对象获取像素数据。据我了解,这可以通过调用 CopyPixels 方法来实现。这个方法需要一个stride参数,我不知道如何获取。据我所知,stride是在读取或复制期间踩入数组时使用的值。任何BitmapSource的适当步幅值是什么?

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?

推荐答案

您可以使用stride = pixel_size * image_width值。例如,对于100像素宽度的RGBA位图,stride = 400。

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

某些应用程序可能需要特殊的行对齐。例如,Windows GDI位图需要32位行对齐。在这种情况下,对于宽度= 33的RGB位图,应将步幅值33 * 3 = 99更改为100,以在目标数组中进行32位行对齐。

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.

通常,您应该了解目标阵列要求。在没有特殊要求的情况下,使用默认的pixel_size * image_width。

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

这篇关于BitmapSource.CopyPixels - 步幅有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:57