I found it hard to locate any easy examples of drawing on Bitmaps using wxPerl. Here is some working code that I put together to see if I could make it work. Just make sure you point the .jpg filename to one that exits on your machine, and you have wxPerl installed. Many thanks to Huub Peters for helping me with Mouse events and understanding DC.
#!/usr/bin/perl -w -- use Wx 0.15 qw[:allclasses]; use strict; use warnings; package MyFrame; use Wx qw[:everything]; use base qw(Wx::Frame); use strict; our $gl_self; sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; $parent = undef unless defined $parent; $id = wxID_ANY unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $sty +le, $name ); $self->SetTitle("Drawing on image"); $gl_self= $self; # Set Global variable for use in EVT handler # Image for drawing on $self->{image1} = Wx::Image->new( 'C:\insert_your_jpeg.jpg', wxBI +TMAP_TYPE_ANY, -1 ); $self->{Loc_Photo_Bmp} = Wx::Bitmap->new( $self->{image1} ) ; $self->{bitmap_1} = Wx::StaticBitmap->new( $self, wxID_ANY, $self- +>{Loc_Photo_Bmp}); # Button to draw image use Wx::Event qw( EVT_LEFT_UP ); $self->{bitmap_1}->SetCursor(wxCROSS_CURSOR); $self->{bitmap_1}->Connect( wxID_ANY,wxID_ANY,wxEVT_LEFT_UP, \&on_ +button ); # # Sizer # $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer_1}->Add($self->{bitmap_1}, 0, 0, 0); $self->SetSizer($self->{sizer_1}); $self->{sizer_1}->Fit($self); $self->Layout(); return $self; } sub on_button{ my ($self, $event) = @_; # select it into a memory dc if (defined $gl_self->{Loc_Photo_Bmp}){ my $mdc = Wx::MemoryDC->new(); $mdc->SelectObject($gl_self->{Loc_Photo_Bmp}); my $pen = Wx::Pen->new( Wx::Colour->new(255,255,255), 3, wxSOL +ID); $mdc->SetPen( $pen ); $mdc->SetBrush( wxTRANSPARENT_BRUSH ); # Determine mouse event # my $m= Wx::MouseEvent->new($event); my $r = 50; my $x=$event->GetX(); my $y=$event->GetY(); # Draw circle round mouse event $mdc->DrawCircle( $x, $y, $r ); $mdc->SelectObject(wxNullBitmap); # deselect the bitmap out of + the DC $gl_self->{bitmap_1} ->SetBitmap($gl_self->{Loc_Photo_Bmp}); $gl_self->{bitmap_1}->SetCursor(wxSTANDARD_CURSOR); $gl_self->{bitmap_1}->Disconnect( wxID_ANY,wxID_ANY,wxEVT_LEFT +_DOWN ); $gl_self->{bitmap_1}->Disconnect( wxID_ANY,wxID_ANY,wxEVT_LEFT +_UP ); } $event->Skip() ; return $self; } 1; package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_1 = MyFrame->new(); $app->SetTopWindow($frame_1); $frame_1->Show(1); $app->MainLoop(); }

In reply to Using wxMemoryDC to draw on a jpeg by Steve_BZ

Title:
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, details, 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, summary, 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.