|
From: Vaughn S. <vau...@in...> - 2007-03-27 19:03:36
|
Mark,
Perl on my end could not locate the method "get_control"; I had to
modify the lines from:
my $canvas = $self->get_control('Canvas');
my $dc = Wx::ClientDC->new( $canvas );
$canvas->PrepareDC( $dc );
to:
my $dc = Wx::ClientDC->new( $self );
$self->PrepareDC( $dc );
Any thoughts as to what could be the problem? After making the changes
it all worked fine (thanks!).
Vaughn
----- Original Message -----
From: "Mark Dootson" <mar...@zn...>
To: "Vaughn Staples" <vau...@in...>
Cc: <wxp...@li...>
Sent: Tuesday, March 27, 2007 2:22 PM
Subject: Re: [wxperl-users] DCPaint Widget Question
Vaughn Staples wrote:
> Mark,
>
> A new question concerning the canvas.
>
> With the drawing objects now complete, I need to save the canvas data
> as
> an image file ... such as a BMP, JPG, or GIF.
Hi Vaughn
Procedure below shows the basics. You just have to look up the
Wx::FileDialog in the docs and in Wx::Demo to see about selecting
filename / filetype.
Regards
Mark
sub evt_menu_file_save {
my ($self, $event) = @_;
$event->Skip(1); # allow event to be processed by further
handlers
# have user select a file name and type
my $filename = 'c:/testimage.png';
my $imagetype = wxBITMAP_TYPE_PNG;
# get the device context we have drawn on
my $canvas = $self->get_control('Canvas');
my $dc = Wx::ClientDC->new( $canvas );
$canvas->PrepareDC( $dc );
#get the dimensions
my ( $width, $height ) = $dc->GetSizeWH();
# create a bitmap to draw on
my $bmp = Wx::Bitmap->new($width, $height, -1);
# select it into a memory dc
my $mdc = Wx::MemoryDC->new();
$mdc->SelectObject($bmp);
# copy the source dc to the memory dc
$mdc->Blit(0,0,$width,$height,$dc,0,0);
# get our bitmap back by selecting a null bitmap into the memory dc
$mdc->SelectObject(wxNullBitmap);
# create image out of bitmap and save
my $img = Wx::Image->new($bmp);
# $img->SaveFile($filename , $imagetype);
# lets scale it just for fun
my $scaled = $img->Scale(int($width / 2), int($height/2));
$scaled->SaveFile($filename , $imagetype);
}
|