bmpLoc=0;
bmpLoc+= bitmap.bmpInfoHdr.biWidth + 1; //Set it to first cell in file
bmpLoc+= currXCell * cellWidth; //Set it to the right col
bmpLoc+= currYCell * bitmap.bmpInfoHdr.biWidth; //Set it to the right row
''bmpLoc'' is added to the bitmap pointer during fread()s, the whole ''bitmap.bmpyadda.biwidth'' is (guess) the bitmap width, currXCell is the current x cell, and currYCell is the current Y cell. Phew... post was about 10x longer than it needed to be..
Anyway, thanks in advance for any assistance.
Proper way to locate cells in a bitmap?
I''m currently working on a little utility to convert bitmaps with cells containing various frames to an easier-to-use format (doing so has been more trouble that it would''ve been had I just used straight bitmaps, but thats beside the point...) and I have these 4 lines of code to locate the upper-left hand corner of a cell given the current cell X/Y coords and the width/height of the bitmap. Each cell has a 1 pixel border around it, including the ones on the edged of the bmp.
Anyway, it doesn''t seem to be working, and I thought it might be here.. I''ve checked it around 5 times and tried various things, but I''m not too good at visualizing mathematical stuff (even simple algebraic junk.. its a curse.. lets just hope it improves with practice/experience). Well, enough talk, here it is:
Okay, all you need to do is think about your bitmap as containing NxM squares of X+1 width and Y+1 height, where X and Y are the actual width and height respectively.
So, to make matters easier to visualize, I will first calculate the y coordinate, then the x coordinate and then put them together to form the final position.
One of the problems with your code is you never used the height of the cells, which will make it always select the first row of tiles.
PreManDrake
So, to make matters easier to visualize, I will first calculate the y coordinate, then the x coordinate and then put them together to form the final position.
// Get y coordinate in bitmap, skipping the bordery = (curYCell*(cellHeight+1))+1;// Get x coordinate in bitmap, skipping the borderx = (curXCell*(cellWidth+1))+1;// Get final offset into bitmapbmpLoc = (y*bitmap.bmpInfoHdr.biWidth)+x;
One of the problems with your code is you never used the height of the cells, which will make it always select the first row of tiles.
PreManDrake
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement