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
 IE4 AttachedBitmap fails
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

LanceRasmussen

USA
8 Posts

Posted - Jul 15 2011 :  13:56:42  Show Profile  Reply
Under prior IE / Delphi XE, the below code would work. It would load a bitmap and stretch it appropriately to fit the TImage on the form to display.

Under IE4 / Delphi XE, it fails. After the LoadFromFile, the TempBitmap should have height and width values and it does not. So it appears that AttachedBitmap is failing.

Create a test project under XE, put an TImageEnIO and TImage on your form and replace the LoadName value with a PNG file on your machine.

I've had to revert to prior IE components and the new version fails.

Lance


var
TempBitmap : tBitmap;
LoadName : Ansistring;
Flip_It : boolean;
ss : integer;
HeightReal, WidthReal : real;
ControlHeightReal, ControlWidthReal : real;
X_Rect, SourceRect, DestinationRect : tRect;
FillColor, TempColor : tColor;
tempheight : integer;
tempwidth : integer;
FrameWidth : integer;
begin
LoadName := 'TestPng.png';
Flip_It := False;
FrameWidth := 0;
FillColor := clBtnFace;
TempBitmap := tBitmap.Create();
try
ImageEnIO1.AttachedBitmap := TempBitmap;
ImageEnIO1.params.SetDefaultParams;
ImageEnIO1.LoadFromFile(LoadName);
HeightReal := TempBitmap.Height;
WidthReal := TempBitmap.Width;
ControlHeightReal := Image1.Height;
ControlWidthReal := Image1.Width;
if (WidthReal > 0) and ((ControlHeightReal / ControlWidthReal) > (HeightReal / WidthReal)) then begin
tempheight := Trunc(ControlWidthReal * HeightReal / WidthReal);
DestinationRect.Top := ((Image1.Height - tempheight) div 2) + FrameWidth;
DestinationRect.Bottom := DestinationRect.Top + tempheight - FrameWidth;
DestinationRect.Right := Image1.Width - FrameWidth;
end
else
if (WidthReal > 0) and ((ControlHeightReal / ControlWidthReal) < (HeightReal / WidthReal)) then begin
tempwidth := Trunc(ControlHeightReal * WidthReal / HeightReal);
DestinationRect.Left := ((Image1.Width - tempwidth) div 2) + FrameWidth;
DestinationRect.Right := DestinationRect.Left + tempwidth - FrameWidth;
DestinationRect.Bottom := Image1.Height - FrameWidth;
end
else
begin
DestinationRect.Right := Image1.Width - FrameWidth;
DestinationRect.Bottom := Image1.Height - FrameWidth;
end;
with X_Rect do begin
Top := 0;
Left := 0;
Bottom := Image1.Height;
Right := Image1.Width;
end;
TempColor := Image1.Canvas.Brush.Color;
Image1.Canvas.Brush.Color := FillColor;
Image1.Canvas.FillRect(X_Rect);
Image1.Canvas.Brush.Color := TempColor;
Image1.Canvas.StretchDraw(DestinationRect, TempBitmap);
finally
TempBitmap.Free();
end;

end;

fab

1310 Posts

Posted - Jul 15 2011 :  14:33:41  Show Profile  Reply
Are you sure this is a problem of version 4?

In your code, the "IF"s cases do not always assign properly "DestinationRect" variable (case 1 leaves unassigned DestinationRect.Left, case 2 leaves unassigned DestinationRect.Top, case 3 leaves unassigned DestinationRect.Top and DestinationRect.Left). For this reason in my tests StretchDraw doesn't work at all.

In my tests, if I replace...
Image1.Canvas.StretchDraw(DestinationRect, TempBitmap);
...with...
Image1.Canvas.StretchDraw(Rect(0,0,image1.Width, image1.height), TempBitmap);
...it works (I just ignored DestinationRect).
Go to Top of Page

LanceRasmussen

USA
8 Posts

Posted - Jul 15 2011 :  15:36:53  Show Profile  Reply
It still does not function for me.

Test project at http://tinyurl.com/5tk76zk

at this point:

HeightReal := TempBitmap.Height;
WidthReal := TempBitmap.Width;

I should get values. I don't.
Go to Top of Page

LanceRasmussen

USA
8 Posts

Posted - Jul 15 2011 :  15:48:30  Show Profile  Reply
I even broke it down to something simple, like this, and it still does not draw the bitmap.

var
TempBitmap : tBitmap;
LoadName : Ansistring;
begin
LoadName := 'TestPng.png';
TempBitmap := tBitmap.Create();
try
ImageEnIO9.AttachedBitmap := TempBitmap;
ImageEnIO9.params.SetDefaultParams;
ImageEnIO9.LoadFromFile(LoadName);
Image1.Canvas.Brush.Color := self.Color;
Image1.Canvas.FillRect(Rect(0,0, Image1.Width, image1.height));
Image1.Canvas.StretchDraw(Rect(0,0,image1.Width, image1.height), TempBitmap);
finally
TempBitmap.Free();
end;
end;
Go to Top of Page

LanceRasmussen

USA
8 Posts

Posted - Jul 15 2011 :  15:51:56  Show Profile  Reply
I just recompiled the older IE components and recompiled the test app and verified that my prior example and the simplified DO work. But under 4, it does not.
Go to Top of Page

fab

1310 Posts

Posted - Jul 16 2011 :  00:47:34  Show Profile  Reply
I just tested your example with Delphi XE and ImageEn 4.0.0. It works perfectly.

Consider this: no changes are done in AttachedBitmap property and related routines, so the problem could be locate elsewhere.

Another user had problems reading PNG having installed TMS components:

http://www.imageen.com/ieforum/topic.asp?TOPIC_ID=27

Could this be the reason?
Go to Top of Page

LanceRasmussen

USA
8 Posts

Posted - Jul 16 2011 :  13:08:18  Show Profile  Reply
I do have the TMS components. Monday I'll try the suggestion of moving the paths to IE before TMS if it is below.

Thanks for checking!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: