Page 1 of 1
Displaying large image with PicShow

Posted:
November 18th, 2003, 1:25 pm
by wzsun
Hi,
I know PicShow has a constraint when trying to display a large image (2272x1704 resoltuion) on say, a small 640x480 form. It works great when the image size is similar to the form size.
I was thinking perhaps one workaround is to create a dummy TImage, resize the loaded image to the size of the form on this dummy TImage and then transfer it to the LaodedImage. What this means is that the loadedimage's size is the same as the form size.. which will greatly speed up the transition effects as there is no need for any resizing process during transition.
Do you think this is feasible? If so, how do I go about it?

Posted:
November 18th, 2003, 5:32 pm
by Kambiz
Use the following procedure:
- Code: Select all
procedure CopyGraphicToBitmap(Graphic: TGraphic; Bitmap: TBitmap;
MaxWidth, MaxHeight: Integer; ShrinkOnly: Boolean);
var
Width, Height: Integer;
begin
Width := Graphic.Width;
Height := Graphic.Height;
if not ShrinkOnly or (Width > MaxWidth) or (Height > MaxHeight) then
begin
if (MaxWidth / Width) < (MaxHeight / Height) then
begin
Height := MulDiv(Height, MaxWidth, Width);
Width := MaxWidth;
end
else
begin
Width := MulDiv(Width, MaxHeight, Height);
Height := MaxHeight;
end;
end;
Bitmap.Width := Width;
Bitmap.Height := Height;
with Bitmap.Canvas do StretchDraw(ClipRect, Graphic);
end;
For example:
- Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
CopyGraphicToBitmap(Image1.Picture.Graphic, PicShow1.Picture.Bitmap,
PicShow1.Width, PicShow1.Height, True);
end;
Access Violation error

Posted:
November 22nd, 2003, 1:28 am
by wzsun
Hi,
I tried pasting the code to the Main.pas as suggested. It runs well with the sample images included in the package. But the moment I click the 'Select Folder' button to specify anotehr folder (where I stored by digital images with sizes 2272 x 1704, it gives me an access violation error...
where else must I put the code?
Better still, why not update the package with the code placed at the correct place.. since it can resolve the 'large image' problem?

Posted:
November 22nd, 2003, 12:48 pm
by Kambiz
You should only change the LoadNextImage procedure as follow:
- Code: Select all
procedure TMainForm.LoadNextImage;
var
Index: Integer;
P: TPicture;
begin
LoadedImage := EmptyStr;
if Pictures.Count > 0 then
begin
repeat
Index := Random(Pictures.Count);
until (Pictures.Count <= 1) or (ShownImage <> Pictures[Index]);
LoadedImage := Pictures[Index];
// PicShow.Picture.LoadFromFile(PicPath + LoadedImage);
P := TPicture.Create;
try
P.LoadFromFile(PicPath + LoadedImage);
CopyGraphicToBitmap(P.Graphic, PicShow.Picture.Bitmap,
PicShow.Width, PicShow.Height, True);
finally
P.Free;
end;
end;
NextFilename.Caption := 'Next: ' + LoadedImage;
NextFilename.Update;
end;
Managing the image in this way inside the component, prevents some functionality of the component (for example exporting the frames). It's the programmer's responsibility to provide the image to the Picshow as the way she/he wants.

Posted:
November 23rd, 2003, 6:17 am
by wzsun
Hi Kambiz,
Yes, it works!!!!!! Thanks for the help and wonderful component.!
Just a suggestion as mentioned previously.. this workaround code may be one solution to resolve loading of large images.. especially if the images are meant to be stretched to fit..
Thanks again!!!!!
WZSun

Posted:
May 23rd, 2007, 1:15 am
by rpoulin
Kambiz wrote:Use the following procedure:
- Code: Select all
procedure CopyGraphicToBitmap(Graphic: TGraphic; Bitmap: TBitmap;
MaxWidth, MaxHeight: Integer; ShrinkOnly: Boolean);
var
Width, Height: Integer;
begin
Width := Graphic.Width;
Height := Graphic.Height;
if not ShrinkOnly or (Width > MaxWidth) or (Height > MaxHeight) then
begin
if (MaxWidth / Width) < (MaxHeight / Height) then
begin
Height := MulDiv(Height, MaxWidth, Width);
Width := MaxWidth;
end
else
begin
Width := MulDiv(Width, MaxHeight, Height);
Height := MaxHeight;
end;
end;
Bitmap.Width := Width;
Bitmap.Height := Height;
with Bitmap.Canvas do StretchDraw(ClipRect, Graphic);
end;
For example:
- Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
CopyGraphicToBitmap(Image1.Picture.Graphic, PicShow1.Picture.Bitmap,
PicShow1.Width, PicShow1.Height, True);
end;
Sorry - What is
Image1.Picture.Graphic in :
procedure TForm1.FormCreate(Sender: TObject);
begin
CopyGraphicToBitmap(
Image1.Picture.Graphic, PicShow1.Picture.Bitmap,
PicShow1.Width, PicShow1.Height, True);
end;
THanks

Posted:
May 23rd, 2007, 10:29 am
by Kambiz
Image1 is a TImage control, which is placed on the form.

Posted:
May 24th, 2007, 2:38 am
by rpoulin
Kambiz wrote:Image1 is a TImage control, which is placed on the form.
OK - a kind of dummy image (not visible).
Thanks