Link to home
Start Free TrialLog in
Avatar of tamnof
tamnof

asked on

bitmap reading - VC++

Howto read bitmap and transform it into tiles collection?
Avatar of gurpreets
gurpreets

I know only the first part.
Actually in VC++ u can't directly load bitmap using MFC support classes .
U have to read the file using header info.
and create a virtual window and using putpixel /putpixelv methods u can write pixel on the virtual window finallly when u call InvalidateRect the paint method will be callled and in paint method  u have to map the the virtual window on the actual physical window.
before reading the file u shold have the knowledge of header of the bitmap.
bitmap is consisting of 50 bytes header and rest all is bitmap data.
in different color format the data is having different formats
16 color --- > 4 bits per pixel
256 color --- >8 bits per pixel
16 K color --- > 65536 bits per pixel
16 M color --- > 3 bytes per pixel
using the header info u can read the data from file u can allocate memory to the pointers
the header is look like this
struct bitmap_header {
BYTE tag[2] ;  //"B" "M"
DWORD zero  ; // "having zer;
DWORD width ; //
DWORD height ; //
WORD bytes_per_pixel ; //

};

 
You mean a pixel in "16K color," which I have presonally never heard of, contains 8192 bytes per pixel?  Do I see a tpyo?    :-)
Avatar of tamnof

ASKER

The answer gives to many asumes... It does not gives me a solution or a start for a solution (like how to read BITMAPINFO structure using CArchive & CFile). Also, the comment placed by thresher_shark, concerns with gurpreets's answer, points to a some-how doubt about the conection between my question and gurpreets's answer.
Avatar of tamnof

ASKER

I'd don't necessarily, need to show the bitmap, what I realy need is to read the bitmap's information and then to divide it into tiles which will form a new file which will consist of collection of tiles.
                           Thanks
I think the most convenient would be:
1. You can use ::LoadBitmap() (it will return a handle to bitmap or NULL) to load your sorce bitmap
2. Then use ::CreateDibSection() to create the destination (if you have no limitations to the destination bitmap format, the best would be 24bpp or 8bpp)
3. Create two memory DCs with ::CreateDC() or CDC::CreateCompatibleDC()
4. insert destination and source into their DCs
5. use ::BitBlt() or CDC::BitBlt() to paint your destination
6. since you've used ::CreateDibSection() for creating destination you have a pointer to the bitmap's data, so you can store the destination file you wrote about
7. restore original bitmaps to DCs and free everything
Is that what you wanted to do?
Something I've forgotten about
instead of ::LoadBitmap() use ::LoadImage() to load it from the disk file
Avatar of tamnof

ASKER

wirus' answer was good but did not cover an important part of my question which is "...not necessarily, need to show the bitmap, what I realy need is to read the bitmap's information and then to divide it into tiles which will form a new file which will consist of collection of tiles. "
             I think wirus's realy knows what he is talking about - I already have done this part. I'll live the un-handled part for next attempts to answer.
                         Thanks tamnof
Can you strictly define: how "file consisting of collection of tiles" should look like?

I thought you had bitmap like this:

XAYSAAS
HHSJAGD

and wanted it to look like this:

X|A|Y|S|A|A|S
-------------------
A|A|S|K|D|J|J

where '|' and '-' are any graphic images separating your tiles (can be black, of course)

One more...
Using DC doesn't mean you have to show the bitmap,
so- look above ("Can you...") :)
Avatar of tamnof

ASKER

Hi wirus
The tile-collection-file in need to create is a file with a common header, specifying the common attributes of all the tiles (since they all have te same dimention) and after the header, the tiles, controled by CTile class objects (user defined class), will bw serialized in a well controled order into the new created file.
An important part of the header shoud be a table which will give the offset BYTE, from the begining of the file, where each tile starts.
                    Thnks
ASKER CERTIFIED SOLUTION
Avatar of wirus
wirus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tamnof

ASKER

I've already done it all by myself almost the same as wirus' proposing.
               tahnks.