bitmapdata中stride的含义.. [英] meaning of stride in bitmapdata..

查看:1714
本文介绍了bitmapdata中stride的含义..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位图并使用lockbits方法来监视名为rgbvalues的数组中的RGB值。

代码就像这样

i have a bitmap and used lockbits method to stare RGB values in an array called rgbvalues.
the code is like this

Bitmap bmp = new Bitmap("c:\\kolam333.jpg");

            // Lock the bitmap's bits.  
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
            System.Drawing.Imaging.BitmapData bmpData =
                bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                bmp.PixelFormat);

            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;
            int [,]array2d=new int[bmp.Width,(bmp.Height)*3];
           
            // Declare an array to hold the bytes of the bitmap. 
            int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
          
            byte[] rgbValues = new byte[bytes];
            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

实际问题是,位图的高度是576,宽度是590.



我想将rgb的所有值从单维数组rgbvalues复制到二维数组中。



2d阵列的总大小是1019520,即576 * 590 * 3。使用3是因为有3个值是rgb但是rgbvalues大小是1020672,这是根据这个语句计算的

The actual problem is, the height of bitmap is 576 and width is 590.

I want to copy all values of rgb into a 2 dimensional array from a single dimension array rgbvalues.

Total size of 2d array is 1019520 i.e 576*590*3. 3 is used because 3 values are there rgb but rgbvalues size is 1020672, which is calculated from this statement

int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbvalues =new byte[bytes];

rgbvalues和2d arraya的大小都不同。怎么样?究竟是什么步骤?

Both sizes of rgbvalues and 2d arraya are different. How? What exactly is stride here?

推荐答案

Stride是存储图像一行所需的字节数。它并不总是与图像宽度相同,这就是为什么必须在此计算中使用Stride。
The Stride is the number of bytes taken to store one row of an image. It''s not always the same as the image width, which is why the Stride must be used in this calculation.


这篇关于bitmapdata中stride的含义..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆