#!/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 your 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;