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

I am looking into migrating to wxPerl for doing some GUI work, and I've come across a problem working with bitmaps, specifically scaling them. Most examples use the Wx::Image->Scale->ConvertToBitmap() methodology, but the ConvertToBitmap routine is no longer in the wxPerl package.

In the wxWidgets documentation, reference is made to using the wxBitmap constructor in place of ConvertToBitmap, but it isn't clear that wxPerl has implemented that constructor. The following code shows a simplified version of what I am trying to do:

use Wx; package MyApp; use strict; use vars qw(@ISA); @ISA = qw(Wx::App); sub OnInit { my( $this ) = @_; my( $frame ) = MyFrame->new( undef, -1, "Image Resize", [100, 100], [450, 300] ); $frame->Show( 1 ); return 1; } package MyFrame; use strict; use vars qw(@ISA); use Wx qw(wxBITMAP_TYPE_BMP); @ISA = qw(Wx::Frame); sub new { my $class = shift; my $this = $class->SUPER::new(@_); my $image = Wx::Image->new('print.bmp',wxBITMAP_TYPE_BMP)->Scale(3 +2,32); # my $bmp = $image->ConvertToBitmap(); old way, no longer supporte +d my $bmp = ???; $this->{ImageViewer}= Wx::StaticBitmap->new($this, -1, $bmp); $this; } package main; my $app = MyApp->new(); $app->MainLoop();
So my question is what to put in place of the ??? to get a bitmap, which can be used in StaticBitmap, from the scaled image.

Thanks,
Jon

Replies are listed 'Best First'.
Re: scaling wxPerl bitmaps
by PodMaster (Abbot) on Dec 14, 2005 at 08:22 UTC
    Simply use
    my $bmp = Wx::Bitmap->new($image);
    If it doesn't work, you'll get an error, if it does, you won't :)
    C:\>perl -MWx -e"warn Wx::Bitmap->new(Wx::Image->new)" Wx::Bitmap=SCALAR(0x22516c) at -e line 1. C:\>
    The wxPerl wxBitmap documentation ought to say its supported, but I've got an outdated version, so I can't check.

    Since this wasn't available in early wxPerl's, you should

    use Wx 0.25;

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.