DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying large image with PicShow

 
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
wzsun
Member


Joined: 31 Jul 2003
Posts: 6

PostPosted: 18/11/03 13:25    Post subject: Displaying large image with PicShow Reply with quote

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?
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 234

PostPosted: 18/11/03 17:32    Post subject: Reply with quote

Use the following procedure:

Code:
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:
procedure TForm1.FormCreate(Sender: TObject);
begin
  CopyGraphicToBitmap(Image1.Picture.Graphic, PicShow1.Picture.Bitmap,
    PicShow1.Width, PicShow1.Height, True);
end;
Back to top
View user's profile Send e-mail Visit poster's website
wzsun
Member


Joined: 31 Jul 2003
Posts: 6

PostPosted: 22/11/03 01:28    Post subject: Access Violation error Reply with quote

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?
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 234

PostPosted: 22/11/03 12:48    Post subject: Reply with quote

You should only change the LoadNextImage procedure as follow:

Code:
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.
Back to top
View user's profile Send e-mail Visit poster's website
wzsun
Member


Joined: 31 Jul 2003
Posts: 6

PostPosted: 23/11/03 06:17    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group