ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 StretchDraw issue
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

kalyani

India
5 Posts

Posted - Apr 18 2016 :  02:01:11  Show Profile  Reply
We are facing issue with StretchDraw function.
We are trying to print one image on canvas.
we are applying scale to that image according to space which we have.
But after drawing this image with StretchDraw function, image is getting stretched more in width according to available space.
So the image we are getting are not in the proper dimensions.
StretchDraw is not working properly at all.
What to do o get image in proportion.

kk

xequte

39053 Posts

Posted - Apr 18 2016 :  03:29:45  Show Profile  Reply
Hi

Please show us your code, and attach a few images that show what is occurring.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

kalyani

India
5 Posts

Posted - Apr 18 2016 :  03:36:42  Show Profile  Reply
function TBaseReport.fuPrintImage(FilePath: string;
PrintImageRequest: TPrintImageRequest): Integer; //PrintImageRequest has image parameters in mm
var
imageParameter: TImageParameter;
lRatio: Real;
lScale: Real;
lImgRatio: Real;
imageWidth,imageHeight :Double; //actual image height, width
lLeft, lTop, lRight, lBottom, lspaceBetImagePrintArea: double;
begin
Result := -1;

if (not Assigned(PrintImageRequest)) or (not Assigned(PrintImageRequest.imageParameter)) then
exit;

imageParameter := PrintImageRequest.imageParameter;

lLeft := imageParameter.Left;
lTop := imageParameter.Top;
lRight := imageParameter.Right; //width
lBottom := imageParameter.Bottom; //height

lspaceBetImagePrintArea := PrintImageRequest.SpaceBetImageAndRect;

imageWidth := MmToPxX(lRight - lspaceBetImagePrintArea);
imageHeight := MmToPxY(lBottom - lspaceBetImagePrintArea);

lScale := 1;

Result := MmToPxY(lBottom); //result in pixel

with uCurCanvas do
begin
try
try
if (FileExists(FilePath)) then
begin

LoadImageFromFile(FilePath);

if (PrintImageRequest.PrintWithRatio) and (ImageEn.IsEmpty = false) then
begin
lRatio := MmToPxY(imageParameter.Bottom) / MmToPxX(imageParameter.Right);

imageHeight := ImageEn.Bitmap.Height; // actual image ht, wd
imageWidth := ImageEn.Bitmap.Width;
lImgRatio := imageHeight / imageWidth;

if lImgRatio >= lRatio then
lScale := MmToPxY(imageParameter.Bottom) / imageHeight
else
lScale := MmToPxX(imageParameter.Right) / imageWidth;
end;
end;

if PrintImageRequest.DrawRectangeAroundImage then
begin
Rectangle(MmToPxX(lLeft), MmToPxY(lTop), MmToPxX(lRight), MmToPxY(lBottom));
end;

if (ImageEn.IsEmpty = false) then
begin
StretchDraw
(Rect(
MmToPxX(lLeft + 1),
MmToPxY(lTop + 1),
Trunc(imageWidth * lScale),
Trunc(imageHeight * lScale)), ImageEn.Bitmap);
end;


Result := MmToPxY(imageParameter.Bottom - 1); //result in pixels

except
on Ex: Exception do
fuShowMsg('TBaseReport.fuPrintImage' + cNEW_LINE + Ex.message, 1);
end;
finally
ImageEn.Blank;
end; //finally
end; //with uCurCanvas do
end;

kk
Go to Top of Page

kalyani

India
5 Posts

Posted - Apr 18 2016 :  03:44:55  Show Profile  Reply




kk
Go to Top of Page

kalyani

India
5 Posts

Posted - Apr 18 2016 :  03:47:40  Show Profile  Reply
above was the original image and here is the image after StretchDraw



kk
Go to Top of Page

xequte

39053 Posts

Posted - Apr 18 2016 :  17:13:56  Show Profile  Reply
Hi

This is more of a TCanvas than an ImageEn question.

It looks like you are treating the Rect.Right and Bottom values as width and height, i.e. it should be:

StretchDraw( Rect( MmToPxX(lLeft + 1),
                   MmToPxY(lTop + 1),
                   MmToPxX(lLeft + 1) + Trunc(imageWidth * lScale),
                   MmToPxY(lTop + 1) + Trunc(imageHeight * lScale)),
             ImageEn.Bitmap );


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: