That seems to be a bug in the CopyToGD() method.

It can load the png you write to disk without error.

It can also successfully create a GD image from the data returned by the SaveToData() method:

use Win32::API; use Win32::GUI::DIBitmap; use GD; $GetDC = new Win32::API('user32','GetDC',['N'],'N'); my $dc = $GetDC->Call(0); my $dib = newFromDC Win32::GUI::DIBitmap ($dc); $dib->SaveToFile("DIBitmap.png"); #my $GDimage = GD::Image->newFromPng( "DIBitmap.png", 1 ); my $mem = $dib->SaveToData( Win32::GUI::DIBitmap::GetFIFFromFormat( 'P +NG' ) ); my $GDimage = GD::Image->newFromPngData( $mem, 1 ); open (DISPLAY, ">GD.png"); binmode DISPLAY; print DISPLAY $GDimage->png; close (DISPLAY);

You should raise a bug report with the author.

The problem probably stems from the mismatch between the version of the GDImageStruct used by DIBitmap & the version used by the latest GD incarnations:

Compare: (<)C:\test\GDstruct.gd (3146 bytes) with: (>)C:\test\GDstruct.dib (3124 bytes) 63,67c63 < /* There should NEVER BE ACCESSOR MACROS FOR ITEMS BELOW HERE, s +o this < part of the structure can be safely changed in new releases. +*/ < < /* 2.0.12: anti-aliased globals. 2.0.26: just a few vestiges aft +er < switching to the fast, memory-cheap implementation from PHP-gd +. */ --- > /* 2.0.12: anti-aliased globals */ 71a67,78 > unsigned char **AA_opacity; > int AA_polygon; > /* Stored and pre-computed variables for determining the perpend +icular > distance from a point to the anti-aliased line being drawn: * +/ > int AAL_x1; > int AAL_y1; > int AAL_x2; > int AAL_y2; > int AAL_Bx_Ax; > int AAL_By_Ay; > int AAL_LAB_2; > float AAL_LAB; 79,82d87 < < /* 2.1.0: allows to specify resolution in dpi */ < unsigned int res_x; < unsigned int res_y; 84,85d88 < <

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".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

In reply to Re^3: Convert DIBitmap to GD by BrowserUk
in thread Convert DIBitmap to GD by iea

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.