Re: Reloading a Bitmap

[email protected] (Steve Cookson - gmail)
Newsgroups perl.wxperl.users
Message-ID <[email protected]>
Hi James,

On 18/06/15 15:19, James Lynes wrote:
>
> SetBitmap works, as in:
>
> Â Â Â  $frame->{bmp} = Wx::Bitmap->new("dwf.png", wxBITMAP_TYPE_PNG);
> Â Â Â  $frame->{sbm}->SetBitmap($frame->{bmp});
>
> Where $frame->{sbm} is a Static Bitmap.
Ok, mine works too, I don quite know why the demo doesn't.  I write all 
over my bitmap and refresh it all the time.
>
> When I create a new bitmap assigned to $frame->{sbm}, is the system 
> reclaiming the memory used by the old bitmap?
I don't know about this, but it would be a property of the wxWidgets 
c-code, so it would be a question for their mailing list.  To avoid 
issues whenever I scale an image for something, I save a copy of the 
scaled image which I then use as the source next time.  Scaled images 
use up very little disc space compared to videos and so on.
>
> I saw in the wxWidgets docs that there is a Bitmap method 
> newFromPNGData that appears to not be wrapped. This would be useful if 
> it would bypass the need to write/read to/from disk everytime the PNG 
> file changes.
>
In the absence of this being wrapped, you can just use Wx::Image and 
it's methods of you can Select it into a device context (eg 
Wx::MemoryDC) like this:

         my $mdc = Wx::MemoryDC->new();
         $mdc->SelectObject($frame->{bmp});         # Having stored your 
bitmap from before
         my $pen = Wx::Pen->new( $colourData, 3, wxSOLID);
         $mdc->SetPen( $pen );
         $mdc->SetBrush( wxTRANSPARENT_BRUSH );
         # Determine mouse courdinates
         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
         $frame->{sbmp}->SetBitmap(frame->{bmp});

As you do in your linear panel meter.

Regards

Steve.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.