Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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: 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.

In reply to wxPerl: how to display a resizing image? (StaticBitmap doesn't seem to work)? by HelenCr

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    What's the matter? Cat got your tongue?...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2018-04-23 23:44 GMT
    Find Nodes?
      Voting Booth?