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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 IE4 AttachedBitmap fails

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
LanceRasmussen Posted - Jul 15 2011 : 13:56:42
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;
6   L A T E S T    R E P L I E S    (Newest First)
LanceRasmussen Posted - Jul 16 2011 : 13:08:18
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!
fab Posted - Jul 16 2011 : 00:47:34
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?
LanceRasmussen Posted - Jul 15 2011 : 15:51:56
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.
LanceRasmussen Posted - Jul 15 2011 : 15:48:30
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;
LanceRasmussen Posted - Jul 15 2011 : 15:36:53
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.
fab Posted - Jul 15 2011 : 14:33:41
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).