#### Archived

This topic is now archived and is closed to further replies.

# Using bitmaps to generate heigh fields

This topic is 6585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Anyone know of a good tutorial to extract darkness intesity out of a bitmap to generate an array of heights? Using DX thanks Lep

##### Share on other sites
What do you mean extract darkness intensity. Just create is as a greyscale, black = lowest height, white = highest height.

*** Triality ***

##### Share on other sites
What do you mean extract darkness intensity. Just create it as a greyscale, black = lowest height, white = highest height.

*** Triality ***

##### Share on other sites
Well, since a bitmap is basicly a matrix. Tranforming a bitmap into a height map is relitivly simple.

  // Heres What You Need To Declarestruct BGRENTRY // RGB bitmaps are realy in BGR order, don''t ask why{ UCHAR byBlue; UCHAR byGreen; UCHAR byRed;};UCHAR *byImgData; // This Contains Data From The Bitmap (RGB encoded)BGRENTRY Bitmap;float *fHeightMap;// LOAD BITMAP DATA INTO byImgData (Source Not Included) // FROM NOW ON, bmpdata WILL SPECIFY DATA TO BE TAKEN FROM THE // BITMAPS HEADERbitmap = new(BGRENTRY [bmpdata.width] [bmpdata.height]); // Syntax Error?for (int i, j = 0; i <= (bmpdata.width - 1) && j <= (bmpdata.height - 1); ){ bitmap[j].blue = byImgData[(i * 3) + 0]; bitmap[i][j].green = byImgData[(i * 3) + 1]; bitmap[i][j].red = byImgData[(i * 3) + 2]; if (i < (bmpdata.width - 1)) { i++; } else if (i = (bmpdata.width - 1)) { j = j + 1; i = 0; } else { //This Would Be Bad News //BAIL!! }}fHeightMap = new(float [bmpdata.width][bmpdata.height]);// THE FOLLOWING SECTION NEEDS A FUNCTION float Value(UCHAR byNumber)// THIS NUMBER SHOULD TAKE A HEX NUMBER AND MAKE IT INTO A FLOAT// SORRY I DON''T HAVE TIME TO INCLUDE ITfor (i, j = 0; i <= (bmpdata.width - 1) && j <= (bmpdata.height - 1){ fHeightMap[i] [j] = ( (Value(bitmap[i] [j]) * Value(bitmap[i] [j]) * Value(bitmap[i] [j]))/ 3); if (i < (bmpdata.width - 1)) { i++ } else if (i = (bmpdata.width - 1)) { j = j + 1 i = 0; } else { //This Would Be Bad News //BAIL!! }}

That should be it. It should create a X by Y Matrix of floats. The floats will be a adverage of the Red, Green and Blue Values. Which means (255, 255, 255) will return 255. This means that color bitmaps will work as well as black and white bitmaps.

Good Enough?

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013224
×