Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2008, 11:10 PM
gopal gopal is offline
Member
 
Join Date: Jun 2007
Posts: 94
Default How to Tile Image with Height

Hi I am using this function ti tile image.but it is working only with width.it is not getting tile with height.

Function TForm1.TileImage(Img : TImage;Sender: TObject): Boolean;
var
x, y : Integer;
Bmp : TBitMap;
begin
Try
Bmp := Img.Picture.Bitmap;
with (Sender as TImage) do
begin
for x := 0 to (Width div bmp.Width) do
for y := 0 to (Height div bmp.Height) do
//Canvas.Draw(x * bmp.Width, y * bmp.Height, bmp);
if (x mod 2)=0 then
Canvas.Draw(x * bmp.Width, y * bmp.Height, bmp)
else
Canvas.Draw(x * bmp.Width, y * bmp.Height, bmp);
end;
Finally
bmp.Free;
End;
Result := True;
end;

can any one tell me what should i do to tile image with height?
Tahnks In Advance
Reply With Quote
  #2  
Old 09-29-2008, 12:07 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default RE: How to Tile Image with Height

div is rest after division.

I think you haven't got enough space left to draw on (thumbnail is partial). With this construction It'll never draw, unless it can fully fit the height...

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #3  
Old 09-29-2008, 12:09 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default RE: How to Tile Image with Height

div is rest after devision is wrong explained...

div is the truncated result of a devision...

Sorry, wasn't that awake, back to the coffee...

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #4  
Old 09-29-2008, 12:11 AM
gopal gopal is offline
Member
 
Join Date: Jun 2007
Posts: 94
Default RE: How to Tile Image with Height

sorry did not got you...
then what shuld i do can you made changes in function so that it can draw in height also?
Reply With Quote
  #5  
Old 09-29-2008, 12:49 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default RE: How to Tile Image with Height

Make sure the height is enough to display the full thumbnail or make your routine draw it partionally...

As told you, the routine you have only draws if there's enough room to draw the FULL height (1 pixel to large is already a not-draw)...

But instead of drawing all this yourself (with the small issues you already have), why not use a TDrawGrid ???

Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #6  
Old 09-29-2008, 02:21 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: How to Tile Image with Height

[pre]
Should do it...

[/pre][DELPHI]
var
x, xx, y, yy : integer;
bmp : TBitmap;
begin
bmp := TBitmap.Create;
try
xx := Image1.Picture.Width;
yy := Image1.Picture.Height;

bmp.PixelFormat := pf24bit;
bmp.Width := xx;
bmp.Height := yy;
bmp.Canvas.Draw(0, 0, Image1.Picture.Graphic);

y := 0;
while y <= Image1.Height do begin
x := 0;
while x <= Image1.Width do begin
Image1.Canvas.Draw(x, y, bmp);
Inc(x, xx);
end;
Inc(y, yy);
end;
finally
bmp.Free;
end;
end;

[/DELPHI][pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
  #7  
Old 09-29-2008, 10:19 PM
gopal gopal is offline
Member
 
Join Date: Jun 2007
Posts: 94
Default RE: How to Tile Image with Height

Sorry it's not working
Reply With Quote
  #8  
Old 09-30-2008, 02:49 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: How to Tile Image with Height

[pre]
It works, the problem is that you are assuming that TImage's canvas
property is the control's canvas. The canvas property of TImage is
actually the bitmap's canvas as drawn by the TImage. If the bitmap
is 50 x 50 then the canvas will be 50 x 50, irregardless of the size
of the TImage itself.

Also keep in mind that the canvas property is only available if the
graphic (picture) is a TBitmap.

Assign a bitmap smaller than the TImage, and then try the following
to see the results. Of course once the bitmap has been resized it
will no longer tile the image.

[/pre][DELPHI]
procedure TForm1.Button1Click(Sender: TObject);
var
x, xx, y, yy : integer;
bmp, bmp2 : TBitmap;
begin
bmp := TBitmap.Create;
try
xx := Image1.Picture.Width;
yy := Image1.Picture.Height;

bmp.PixelFormat := pf24bit;
bmp.Width := xx;
bmp.Height := yy;
bmp.Canvas.Draw(0, 0, Image1.Picture.Graphic);

//Following will resize the Image's bitmap
if MessageBox(Handle,
'Resize the bitmap?',
'Confirm',
MB_ICONQUESTION OR MB_YESNO) = IDYES then
begin
bmp2 := TBitmap.Create;
try
bmp2.Width := Image1.Width;
bmp2.Height := Image1.Height;
Image1.Picture.Assign(bmp2);
finally
bmp2.Free;
end;
end;

y := 0;
while y <= Image1.Height do begin
x := 0;
while x <= Image1.Width do begin
Image1.Canvas.Draw(x, y, bmp);
Inc(x, xx);
end;
Inc(y, yy);
end;
finally
bmp.Free;
end;
end;
[/DELPHI][pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.