I gang

Delphi Graphic Sizing

I have a routine that Sizes a JPG, PNG, or GIF. I'm doing something wrong because the resulting graphic often doesn't display. I also need to enhance the procedure to provide various sizing options, ex: Stretch, Fit, Crop, etc.

Here is the current routine:

Procedure SizeImage(ExpressionResource:TECExpressionResource);

var FromFilePath,ToFilePath:string;

MaxWidth,MaxHeight:integer;

Picture: TPicture;

Bitmap: TBitmap;

FixedCanvas:TBitmap;

NewArea:TRect;

OldAspectRatio,NewAspectRatio:double;

Scale:double;

LeftOffset,TopOffset:integer;

ExactCanvasSize:boolean;

begin

FromFilePath:=[url removed, login to view]('1',[ERRMissing,ERRInvalid]);

ToFilePath:=[url removed, login to view]('2',[ERRMissing,ERRInvalid]);

MaxWidth:=[url removed, login to view]('3');

MaxHeight:=[url removed, login to view]('4');

ExactCanvasSize:=[url removed, login to view]('5',[ERRMissing,ERRInvalid]);

[url removed, login to view]:=0;

[url removed, login to view]:=0;

NewAspectRatio:=MaxHeight/MaxWidth;

Picture := [url removed, login to view];

try

[url removed, login to view](FromFilePath);

Bitmap := [url removed, login to view];

try

OldAspectRatio:=[url removed, login to view];

if NewAspectRatio<OldAspectRatio then

Scale:=MaxHeight/[url removed, login to view]

Else

Scale:=MaxWidth/[url removed, login to view];

[url removed, login to view]:=round([url removed, login to view]*Scale);

[url removed, login to view]:=round([url removed, login to view]*Scale);

[url removed, login to view]:=[url removed, login to view];//round(MaxWidth*scale);

[url removed, login to view]:=[url removed, login to view];//round(MaxHeight*scale);

[url removed, login to view](0, 0, [url removed, login to view]);

[url removed, login to view](NewArea,Bitmap);

[url removed, login to view]:=[url removed, login to view];

[url removed, login to view]:=[url removed, login to view];

if ExactCanvasSize then

Begin

Try

//Determine Offset to center in canvas

LeftOffset:=round(([url removed, login to view])/2);

TopOffset:=round(([url removed, login to view])/2);

if LeftOffset<0 then LeftOffset:=0;

if TopOffset<0 then TopOffset:=0;

//Create A fixed Canvas bitmap and place image here

FixedCanvas:=[url removed, login to view];

[url removed, login to view]:=MaxWidth;

[url removed, login to view]:=MaxHeight;

[url removed, login to view](LeftOffset,TopOffset,Bitmap);

[url removed, login to view](ToFilePath);

Finally

[url removed, login to view];

End;

End

Else

[url removed, login to view](ToFilePath);

finally

[url removed, login to view];

end;

finally

[url removed, login to view];

end;

[url removed, login to view];

End;

Færdigheder: Delphi

Se mere: picture sizing, enhance picture, canvas crop, scale crop, free gif picture, delphi gif, image sizing, enhance scale image, image stretch, delphi string, bitmap png, delphi bitmap minimized window, draw bitmap, image height gif, round graphic, gif crop, template sizing graphic novels, image maxheight, graphic delphi, delphi image fit, delphi display, delphi crop image, algorithm graphic delphi, image delphi, need delphi free

Om arbejdsgiveren:
( 13 bedømmelser ) Logan, United States

Projekt-ID: #6030721

Tildelt til:

igors233

Hired by the Employer

$30 USD / time
(38 bedømmelser)
6.1