VoyForums

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1[2]345678910 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 06:30:40 11/06/03 Thu
Author: Azurea Skyes
Subject: Re: Questions about Select
In reply to: Michel 's message, "Re: Questions about Select" on 17:52:45 10/31/03 Fri

Before I saw Michael's final solution to the resize canvas, I had developed something similar... I present it here for those interested.

Procedure ResizeCanvas(cnwidth,cnheight,cnpos : integer; var img : TImageScrollBox);
(*
by Azurea Skyes
This procedure will resize the canvas area of an ImageScrollBox.
The new canvas size has to be larger than the old image size or nothing will happen.
In a future version an exception may be raised if the new canvas size is less then
the existing image. Full exception try/finally blocks have not been used.
Feel free to make this code more robust. I haven't added an undo block yet.

Note: cnpos corresponds to the location of the current image, relative to the new
canvas size. (As seen in programs such as Photoshop). i.e.
1 2 3
4 5 6
7 8 9
*)

var
Graphic,OldGraphic : TDibGraphic;
iheight, iwidth, x, y : integer;

begin
// Determine size of original image
iheight := img.Graphic.Height;
iwidth := img.Graphic.Width;
x := 0;
y := 0;

// Check if new canvas size is larger
if (cnwidth >= iwidth) and (cnheight >= iheight) then
begin

// Create temporary images
Graphic := TDibGraphic.Create;
OldGraphic := TDibGraphic.Create;

// Copy existing graphic to temporary area
if img.Graphic <> nil then OldGraphic := img.Graphic;

// Make empty graphic ready to receive existing image
Graphic.NewImage(cnwidth,cnheight,ifTrueColor,nil,0,0);

// Determine location of pasted image
case cnpos of
1 : begin // top left
x := 0;
y := 0;
end;
2 : begin // top centre
x := (cnwidth - iwidth) div 2;
y := 0;
end;
3 : begin // top right
x := cnwidth - iwidth;
y := 0;
end;
4 : begin // middle left
x := 0;
y := (cnheight - iheight) div 2;
end;
5 : begin // middle centre
x := (cnwidth - iwidth) div 2;
y := (cnheight - iheight) div 2;
end;
6 : begin // middle right
x := cnwidth - iwidth;
y := (cnheight - iheight) div 2;
end;
7 : begin // bottom left
x := 0;
y := (cnheight - iheight);
end;
8 : begin // bottom centre
x := (cnwidth - iwidth) div 2;
y := (cnheight - iheight);
end;
9 : begin // bottom right
x := cnwidth - iwidth;
y := (cnheight - iheight);
end;
end;

// Paste previously saved image
Graphic.Canvas.Draw(x,y,OldGraphic);

// Update our Image Scroll Box with the new image.
img.Graphic := Graphic;
img.Redraw(True);
end;
end;

[ Next Thread | Previous Thread | Next Message | Previous Message ]


Replies:


[ Contact Forum Admin ]


Forum timezone: GMT-5
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.