Please elucidate me about Bitmap question!!
I have a bitmap 32 bit 200x200 (40.000 pixel) with many colors in it...
I would (with c++) get access at a specific pixel (color) for example at the 2480th and change it, for example if it is black change in light red...
how can i do?
I put beforehand i have readen lot''s of tutorial but the only one i find good it was this: http://www.edm2.com/0107/os2bmp.html but now it doesn''t work!! Can u give me not a web page or some url but a good reffering for the specific my trouble!!
Tnx much!
yes but that is much vague can u explain it better please?
what do u mean for pointer_to_bitmap?
what do u mean for pointer_to_bitmap?
When you load the bitmap into a C++ program, you usually receive a pointer to it. Then do what Raab said.
ok, so the pointer at the loaded bitmap image is only a pointer at the first pixel color of the bitmap?
to load a bitmap i can use this function?
HBITMAP LoadBitmap(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpBitmapName // name of bitmap resource
);
[edited by - Link on March 16, 2003 4:34:09 PM]
to load a bitmap i can use this function?
HBITMAP LoadBitmap(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpBitmapName // name of bitmap resource
);
[edited by - Link on March 16, 2003 4:34:09 PM]
I don’t think you have to load the whole bitmap into memory to read and write to it, you should be able to do this directly with the file. If you want to be able to do this successfully you need know the structure the BMP file very well.
I suggest you go to wostit.org and read the BMP file format reference again, if you don’t understand it read it again. Then go to MSDN and lookup the structures used in the bitmap file ie. BITMAPFILEHEADER, BITMAPINFOHEADER, etc. You might even want to get a hex editor or some other tool that allows you to examine the bytes in a file and go though and go through the BMP manually with your new found knowledge.
Once you understand completely how the bitmap information is stored in a the file it should be easy for you to write the functions you need to open a bitmap file, locatate the offset to the actual pixel information, read a specific pixel (of a specific number of bits) and write the new pixel.
Another option is to use a library such as SDL or DirectDraw, load the BMP into a suface change the pixel data of the surface and then save it to another BMP file.
Hope that helps, Cheers.
I suggest you go to wostit.org and read the BMP file format reference again, if you don’t understand it read it again. Then go to MSDN and lookup the structures used in the bitmap file ie. BITMAPFILEHEADER, BITMAPINFOHEADER, etc. You might even want to get a hex editor or some other tool that allows you to examine the bytes in a file and go though and go through the BMP manually with your new found knowledge.
Once you understand completely how the bitmap information is stored in a the file it should be easy for you to write the functions you need to open a bitmap file, locatate the offset to the actual pixel information, read a specific pixel (of a specific number of bits) and write the new pixel.
Another option is to use a library such as SDL or DirectDraw, load the BMP into a suface change the pixel data of the surface and then save it to another BMP file.
Hope that helps, Cheers.
where can i find hex editor?
Can u explain me how can i do it:
Can u explain me how can i do it:
quote:
Another option is to use a library such as SDL or DirectDraw, load the BMP into a suface change the pixel data of the surface and then save it to another BMP file.
First, are you sure you want to directly access bitmap''s memory? You can use SetPixel function to set pixels (it''s slow, though).
I''m not absolutely sure about this, but LoadImage function allows you to specify LR_CREATEDIBSECTION flag, when loading a bitmap, and then, you can call GetObject function (if I''m rigth about this) to obtain the DIBSECTION structure, and the bmBits member of the BITMAP structure contained within the DIBSECTION will contain a pointer to the bitmap''s bit values.
More info here
If this doesn''t work you can create DIBSection (it''s a bitmap, which memory you can access directly) and copy bitmap to it.
I''m not absolutely sure about this, but LoadImage function allows you to specify LR_CREATEDIBSECTION flag, when loading a bitmap, and then, you can call GetObject function (if I''m rigth about this) to obtain the DIBSECTION structure, and the bmBits member of the BITMAP structure contained within the DIBSECTION will contain a pointer to the bitmap''s bit values.
More info here
If this doesn''t work you can create DIBSection (it''s a bitmap, which memory you can access directly) and copy bitmap to it.
You could always copy the bitmap loader from nehe''s site or gametutorials (don''t know which one of them is best, may be the same source), and then load the bitmap into memory and then change the pixel the way Raab314159, that way you can dynamically change the image every frame, thus allowing you to have really nice effects on it, even if you use the bitmap as a texture.
When you load the image using a bitmap loader you get a imagedata pointer, where you have direct access to the loaded image, and can change every pixel anyway you want to.
One little problem is that you are using 32bit bitmap, which is rather unstandard (24 bit is the most common one, 32 bits means you have a alpha channel) so you might have to change the code some to be able to access the alpha channel...
A really good hex editor I know of is Hex Workshop, and there is a shareware version available from http://www.bpsoft.com/
I hope this info helps you, playing with bitmaps is fun and easy, you could try experimenting with 256 color bitmaps first, as they are VERY easy to read, and then advance to 24bit bitmaps, but 256 colors is rather limited.
When you load the image using a bitmap loader you get a imagedata pointer, where you have direct access to the loaded image, and can change every pixel anyway you want to.
One little problem is that you are using 32bit bitmap, which is rather unstandard (24 bit is the most common one, 32 bits means you have a alpha channel) so you might have to change the code some to be able to access the alpha channel...
A really good hex editor I know of is Hex Workshop, and there is a shareware version available from http://www.bpsoft.com/
I hope this info helps you, playing with bitmaps is fun and easy, you could try experimenting with 256 color bitmaps first, as they are VERY easy to read, and then advance to 24bit bitmaps, but 256 colors is rather limited.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement