   Pixel values from a Texture using c# & dx9
  Ok banging my head around with this one. I am in the process of writing a very basic terrain engine using a height map of 128x128. I am using C# and Directx 9 SDK. I have loaded my texture but am unsure how to access the pixel values that would correspond to the height coordinates that i require (either r,g or b):/* my code */m_nHeightArray = new short[256,256];m_vTexMap = TextureLoader.FromFile(device,"heightmap.bmp");//how do i get the pixel values from the texture /*example needed*/?I have found a good example of a terrain engine in C++ (some code below) and am basing my engine on its functionality, but cannot figure out the correct direction to take./* example i have found */D3DLOCKED_RECT lockedrect;::ZeroMemory(&lockedrect, sizeof(lockedrect));rslt=m_pTextureHeightmap->LockRect(0, &lockedrect, NULL, 0);if(FAILED(rslt)) { return D3DError(rslt, __LINE__, __FILE__, "Could not lock heightmap surface"); }DWORD* pBits=(DWORD*)lockedrect.pBits;int index=0;// Display offset (bytes)=((Pitch * y) + x) * Num Bytes per pixel{for(int y=0; y<256;y+=2){for(int x=0; x<256; x+=2)    {    m_nHeightArray[y][x]=(getr(pBits[(y*256)+x]))/5;    }}Thanks in advance for your help. 
  Loading the value of a pixel at a given location in a bitmap can be done in .NET 1.1 but not 1.0, make sure you have the latest version. Anyway the System.Drawing.Bitmap class has a .GetPixel(int x, int y) function, which will return lots of information about a pixel at that location, like its color, brightness hue, etc. Hope that helps.BTW this means opening the heightmap as a System.Drawing.Bitmap first, this can be imported into a Texture anyway so no problems there.Also if you write code in the forum put it inside [ source ] [/ source ] brackets   [edited by - koniosis on February 18, 2004 7:53:20 AM];  the getpixel method is so slow its hardly worth using,i would suggest accessing the underlying bits of the bitmapusing Bitmap.LockBits()here is a small example on how to access the bitmaps bits // Example of Accessing the bitmaps bitspublic void BitmapBits(Bitmap bmp){   int Width = bmp.Width; // Store Bitmap Width   int Height = bmp.Height; // Store Bitmap height   byte[] Data = new byte[Width*Height*4]; // Create an array of byte''s in the form of ARGB   // Lock the bitmap''s bits   BitmapData bmpd = bmp.LockBits(new Rectangle(0,0,Width,Height),ImageLockMode.WriteOnly,PixelFormat.Format32bppArgb);   //Copy the bitmaps bits from the Scan0 intptr into the Data array   Marshal.Copy(bmpd.Scan0,0,Data,Data.Length);   // Unlock bitmaps bits   bmp.UnlockBits(bmpd);   //Process the Bitmaps bits here};  Thanks koniosis and Zyme. I figured out the GetPixel functionality in the end but i like Zyme''s method which works just as well, plus its a touch faster.Thanx again. 