Displaying large image with PicShow

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Displaying large image with PicShow

Postby wzsun » November 18th, 2003, 1:25 pm

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?
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Postby Kambiz » November 18th, 2003, 5:32 pm

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;
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Access Violation error

Postby wzsun » November 22nd, 2003, 1:28 am

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?
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Postby Kambiz » November 22nd, 2003, 12:48 pm

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.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby wzsun » November 23rd, 2003, 6:17 am

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
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Postby rpoulin » May 23rd, 2007, 1:15 am

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
rpoulin
Active Member
Active Member
 
Posts: 5
Joined: May 18th, 2007, 7:05 am

Postby Kambiz » May 23rd, 2007, 10:29 am

Image1 is a TImage control, which is placed on the form.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby rpoulin » May 24th, 2007, 2:38 am

Kambiz wrote:Image1 is a TImage control, which is placed on the form.


OK - a kind of dummy image (not visible).

Thanks
rpoulin
Active Member
Active Member
 
Posts: 5
Joined: May 18th, 2007, 7:05 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests

cron