SaLz
asked on
A Simple Image Question
hi, what is the name of this http://www.freewebs.com/fordisplay/cButtons.bmp when images are placed within a BMP and how can I do this with delphi?
I suppose that when you say how can I do this with delphi? toy want to know hoe can extract a bitmap of the matrix...
Well... first, the image from
http://www.freewebs.com/fordisplay/cButtons.bmp
is malformed, because it has a size of 136x36 and have 6 colums * 2 rows so... the widths are inconsistent (136 is not multiple of 6) 136/6=22,6666666
Lets suppose that the image is correct, for example, the buttons have 23+18 pixels... you can get the bitmaps with a procedure like this:
procedure TForm1.Button1Click(Sender : TObject);
procedure GetABitmapFromAMosaic( aWidht,aHeight,aCol,aRow:i nteger;Sou rce,Dest: TBitmap);
var
SourceRect,
DestRect :TRect;
begin
//Calculate Rects...
SourceRect:=Rect(aCol*aWid ht,aRow*aH eight,(aCo l*aWidht)+ aWidht,(aR ow*aHeight )+aHeight) ;
DestRect:=Rect(0,0,aWidht, aHeight);
//Copy the bitmap
Dest.Canvas.CopyMode:=cmSr cCopy;
Dest.Canvas.CopyRect(DestR ect,Source .Canvas,So urceRect);
end;
begin
Image2.Canvas.Pixels[0,0]: =66; //Make canvas of Image2 available if it's empty
GetABitmapFromAMosaic(23,1 8,2,0,Imag e1.Picture .Bitmap,Im age2.Pictu re.Bitmap) ;
end;
Well... first, the image from
http://www.freewebs.com/fordisplay/cButtons.bmp
is malformed, because it has a size of 136x36 and have 6 colums * 2 rows so... the widths are inconsistent (136 is not multiple of 6) 136/6=22,6666666
Lets suppose that the image is correct, for example, the buttons have 23+18 pixels... you can get the bitmaps with a procedure like this:
procedure TForm1.Button1Click(Sender
procedure GetABitmapFromAMosaic( aWidht,aHeight,aCol,aRow:i
var
SourceRect,
DestRect :TRect;
begin
//Calculate Rects...
SourceRect:=Rect(aCol*aWid
DestRect:=Rect(0,0,aWidht,
//Copy the bitmap
Dest.Canvas.CopyMode:=cmSr
Dest.Canvas.CopyRect(DestR
end;
begin
Image2.Canvas.Pixels[0,0]:
GetABitmapFromAMosaic(23,1
end;
ASKER
hi Radikal,
hm, i made an image of 46x36, put 2 images on the form and the button and on button click all it does is put a dot on the image2.
what should i do, or am doing wrong ?
ty :)
hm, i made an image of 46x36, put 2 images on the form and the button and on button click all it does is put a dot on the image2.
what should i do, or am doing wrong ?
ty :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ty :)
Lets say each of those images within your big image is a 16x16 small image.
If you tried to add this image to an imagelist, with the imagelist also set to 16x16 it would ask if you want to separate the images into individual ones.
You can recreate something like this by importing lots of small images into an ImageList.
Then close the imagelist to store them. Now re-open the imagelist and click export (dont select any images).
It will now save you all the images into one bmp.