Solved

Splitting a bmp into small pieces

Posted on 2001-07-31
4
211 Views
Last Modified: 2010-04-06
Hi there,
I need a code example of how to split a bmp into small pieces. My problem:

I have a large bmp with tiles on it (for use in a tiled based game) only, it's like 14tiles x 30tiles in size. A tile is 48x48 and there is a 3 pixel sperater around the tiles, ie....

------------------
|    ||    ||    |
|    ||    ||    |
------------------

Kinda like that. I need to know how i can load a bmp up and have eg:

Tile height: ??
Tile width: ??
Skip width: ??
Skip height: ??

The values would be (for my purpose):
48,48,3,3

If anyone can help me, please do so.

Thanks
Stephen
0
Comment
Question by:St3v13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:St3v13
ID: 6338174
Btw, the program will then spit out seperate bmps of the sperate tiles.

Thanks
Stephen
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6338200
sorry had no time to code, but its not so heavy to solve

the heart, beside the calculation is the bitmap.canvas.copyrect-method
or as alternative the bitblt-api funtion
to copy a part from the source bitmap into the new one

meikl ;-)
0
 
LVL 2

Accepted Solution

by:
bugroger earned 195 total points
ID: 6338832
Hi,
 Try this code:

Type
 TXYWH     = Record
              x, y, w, h : integer;
             End;
 TTileXY   = array of TXYWH;


//Calc the XYPos in the Source-Bitmap and
//the width, height
//SkipL/R/T/B are Left, Right, Top, Bottom
Procedure CalcTileXY(VAR _TileXY : TTileXY;
                     horzCount, vertCount, TileHeight, TileWidth,
                     SkipL, SkipR, SkipT, SkipB : Integer);
VAR
 x, y, i : integer;

Begin
 SetLength(_TileXY, horzCount * vertCount);
 i := 0;
 For y := 0 to (vertCount -1) do
  For x := 0 to (horzCount -1) do
  Begin
   _TileXY[i].x := (x * TileWidth) + SkipL;
   _TileXY[i].y := (y * TileHeight) + SkipT;
   _TileXY[i].w := TileWidth - (SkipL + SkipR);
   _TileXY[i].h := TileHeight - (SkipT + SkipB);
   Inc(i);
  End;
End;

// TileNo from 1 to ...
Procedure GetTileBitmap(SourceBitmap : TBitmap; VAR DestBitmap : TBitmap;
                       _TileXY : TTileXY; TileNo : Cardinal);
Begin
 Dec(TileNo);
 DestBitmap.Canvas.CopyRect(
  Rect(0,0, _TileXY[TileNo].w , _TileXY[TileNo].h ),
  SourceBitmap.Canvas,
  Rect(_TileXY[TileNo].x, _TileXY[TileNo].y,
       _TileXY[TileNo].x + _TileXY[TileNo].w,
       _TileXY[TileNo].y + _TileXY[TileNo].h));
End;


Procedure DestroyTileXY(VAR _TileXY : TTileXY);
Begin
 SetLength(_TileXY, 0);
End;

-----------------------------------
example how to use these functions:
-----------------------------------

VAR
 TileXY : TTileXY;
 TileBitmap : TBitmap;

begin
 CalcTileXY(TileXY, 5, 5, 50, 50, 1, 1, 1, 1);
 TileBitmap := TBitmap.Create;
 TileBitmap.Width := TileXY[0].w;
 TileBitmap.height := TileXY[0].h;
 GetTileBitmap(Image1.Picture.Bitmap, TileBitmap, TileXY, StrToInt(Edit1.Text));
 Image2.Canvas.Draw(0,0, TileBitmap);
 DestroyTileXY(TileXY);
 TileBitmap.Free;
end;


GL
 Bug
0
 

Author Comment

by:St3v13
ID: 6338865
Excellent answer! Thanks so much for your time and effort. I hope these 195 points are enough :-)


Regards
Stephen
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question