http://www.perlmonks.org?node_id=1031701

HelenCr has asked for the wisdom of the Perl Monks concerning the following question:

This post is in continuation to wxPerl image handling (short & sweet). and to Steve_BZ's last post there: Re^4: wxPerl image handling (short & sweet)..
Although that thread is 12 years old (and the last post is 3 years old) (they say that good wine only gets better with time), I've found it of interest, and for the benefit of PerlMonks users, I am posting this question, and my experiences.

Steve_BZ: Firstly, I tried to run your script, and it bumps with the same error as that of user "rp{erl}D" in Re^3 above.

I modified your script just a bit, like so:

#!/usr/bin/perl # Taken from: http://permonks.org/?node_id: 794478 use Wx; package MyFrame; # subclass wx::Frame to insert the image control. use vars qw(@ISA); use strict; use Wx qw( wxWidth wxHeight); use IO::File; @ISA=qw(Wx::Frame); sub new { my $class = shift; my $this = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] ); # replace the filename with something appropriate. my $file = IO::File->new( # enter a path and image filename of you +r own: 'D:\My Documents\...\IMG_8053.JPG', "r" ) or return undef; binmode $file; # define a handler for jpeg images. my $handler = Wx::JPEGHandler->new(); my $image = Wx::Image->new(); my $bmp; # used to hold the bitmap. $handler->LoadFile( $image, $file ); $bmp=Wx::Bitmap->new( $image ); if( $bmp->Ok() ) { # create a static bitmap called ImageViewer that displays the + selected image. $this->{ImageViewer}= Wx::StaticBitmap->new($this, -1, $bmp); } my $b1 = Wx::LayoutConstraints->new(); $b1->left->Absolute(0); $b1->top->Absolute(0); $b1->width->PercentOf( $this, wxWidth,100); $b1->height->PercentOf( $this, wxHeight, 100); $this->{ImageViewer}->SetConstraints( $b1 ); $this; # return the frame object to the calling application. } 1; package main; my $app = Wx::SimpleApp->new; my $frame = MyFrame->new( "Mini-image demo", [-1,-1], [-1,-1]); unless ($frame) {print "unable to create frame -- exiting."; return +undef} $frame->Show(1); $app->MainLoop; 1;
and then it does run, but:

1. The "constraints" have no effect!
I used an image of size 3200 x 2400 (pretty normal nowadays), and it does not compress or fit it to the frame size, instead it crops the image to the frame window (in other words, if the frame size is, say, 400 x 300, it shows just a sub-region of 400 x 300 pixels out of that image, without compressing or resizing the image).

2. So the bottom line is: what's the right way to display a resizing image in a frame?

3. and even more importantly: how to display an image in a resizing window, under a sub-panel?

Many TIA - Helen

I am using wxWidgets 2.8.12, Wx version 0.9903, StrawberryPerl 5.16 on a WinXP SP3 platform.