15,964,729 members
0.00/5 (No votes)
See more:
i have a bitmap and used lockbits method to stare RGB values in an array called rgbvalues.
the code is like this
C#
```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);```
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
C#
```int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
byte[] rgbvalues =new byte[bytes];```
Both sizes of rgbvalues and 2d arraya are different. How? What exactly is stride here?
Posted
Updated 30-Apr-13 22:07pm
v2

## Solution 1

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.

Comments
luckycode 1-May-13 3:42am
so..for my probelm..how will i store all rgb values in 2D array..since both dimensions are not same..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Papy@007 35 merano99 35 Pete O'Hanlon 10 Daniel Davis 2024 10 den2k88 5
 OriginalGriff 308 Pete O'Hanlon 170 Dave Kreskowiak 145 merano99 90 Andre Oosthuizen 55

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900