in reply to Memory File and wxPerl

Can this code be modified to use a memory file?

To paraphrase your question: Can Wx::Bitmap->new("rawaudio.png", wxBITMAP_TYPE_PNG) take a filehandle or scalar variable instead of a filename from which to create the bitmap?

Maybe this helps?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Memory File and wxPerl
by jmlynesjr (Deacon) on Mar 18, 2016 at 16:07 UTC

    BrowserUk, nice, concise restatement of my question. I tend to ramble on with background info. :)

    The XPM file approach looks like a very good next thing to try. The wxBook states it's primary use as being for small bitmaps, but 600x600 is still under 400K, so it shouldn't be a memory problem. Thanks for your suggestion. I will post an update when I try it.

    James

    There's never enough time to do it right, but always enough time to do it over...

      The XPM file approach looks like a very good next thing to try.

      Actually, I think anonymonks pointer to newFromBits() is probably a better lead.

      Whilst trying to look at that, I came across newFromPngData() which is described as: "Loads a bitmap from the memory containing image data in PNG format."; and sounds perfect for your purpose.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Findings:

        Base GD can't output to an XPM file. However, I found the CPAN module GD::Convert that adds output options to GD, one of which is XPM. This seems to work as advertised and didn't have a problem creating the 600x600 image memory file.

        NewFromPNGData is not wrapped in Wx. Per Mark Dootson(wxperl-users), the work around is:

        open my $fh, '<', \$buffer; my $bitmap = Wx::Bitmap->new(Wx::Image->new($fh, wxBITMAP_TYPE_PNG));

        This works as well. I plan to try both methods and see if there is any speed difference(currently at a 35msec screen refresh rate). My gut feel is that I might not see a speed increase. The small file size may have been writing/reading within Linux I/O buffers and not from physical disk. More testing needed.

        James

        There's never enough time to do it right, but always enough time to do it over...