in reply to Re: create PNG image
in thread create PNG image

I've tried SetPixel method but couldn't find how to write pixel by pixel in grayscale with 10-bit values(0~1023). Thanks @pixels = $image->GetPixel(x=>1,y=>1); $pixels[0]*=0.5; $image->SetPixel(x=>1,y=>1,color=>\@pixels); # this is color information $image->Quantize(colorspace=>'gray');

Replies are listed 'Best First'.
Re^3: create PNG image
by zwon (Abbot) on Sep 26, 2010 at 03:28 UTC

    Here's some example code:

    use strict; use warnings; use Image::Magick; my $image = Image::Magick->new( size => '1024x100', type => 'Greyscale', depth => 16, ); $image->Read('xc:white'); for ( 0 .. 1023 ) { my $color = sprintf "gray(%2.3f%%)", 100 * $_ / 1023; my $res = $image->Draw( primitive => 'line', stroke => $color, points => "$_,0 $_,100", ); warn $res if $res; } for ( 0 .. 16 ) { $image->SetPixel( x => int( (16 - $_) * 1023 / 16 ), y => 50, color => [ ( $_ / 16 ) x 3 ], ); } my $res = $image->Write( filename => "grey.png" ); warn $res if $res;

    Why are you ignoring Markup in the Monastery? Also there's bold warning below post text area: Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!

    Update: added SetPixel demo