Hi. I'm working on a document scanning and archive system. Documents come off
the scanner as 1-bit (black and white) 600 DPI TIFF files. Until recently I
was converting these to JPG. Then I display the image to the user, to verify
they didn't include extra space or chop anything off, then the user can upload
it to the server.
Previously I had a routine that would take the tiff file, convert it to a JPG,
then open it in a DIBitmap, rescale it there to fit the screen (leaving the
original file intact) and then convert to bitmap to display it. Now we'd like
to keep the image in TIFF format all the way to the server, for quality
reasons. However, when I try open and resize the TIFF with DIBitmap I get a
solid black box where the image should be. I'm sure I'm doing something wrong,
but I'm not sure what. I'll include the relevant code below. Please ignore
the part with Image::Magic doing the JPG conversion... I left it in so you can
see what I WAS doing, and what I am now doing...
I'm wondering if I am doing something wrong, or am missing a piece of software.
But the JPG resize was working perfectly. I'd appreciate any insight into
this very much.
# Log the event and convert to JPG
log_event("Verifying the Image");
$image = Image::Magick->new;
$x = $image->Read("C:\\tmp.tiff");
log_event("Return from ImageMagick->Read: $x");
$p = $image->Append(stack=>true);
log_event("Return from ImageMagick->Append: $p");
$imgmgkres = $scanquality."X".$scanquality;
$p->Set(density=>"$imgmgkres");
$p->Set(quality=>$jpgquality);
$x = $p->Write("C:\\tmp.JPG");
log_event("Return from ImageMagick->Write: $x\tQuality: $jpgquality");
undef $image;
undef $p;
# Open the file in a DIBitmap for display
$dib = newFromFile Win32::GUI::DIBitmap('C:\\tmp.tiff');
$heightimg = $dib->GetHeight();
$widthimg = $dib->GetWidth();
$wmax = 750; $hmax=700;
$hratio = $heightimg/$hmax;
$wratio = $widthimg/$wmax;
# If image needs to be resized, resize it.
if( $hratio> $wratio && $hratio > 1)
{ $dispdib = $dib -> Rescale($widthimg/$hratio, $hmax);
$imgwid=$widthimg/$hratio; $imglen=$hmax;}
elsif( $wratio>=$hratio && $wratio > 1)
{ $dispdib = $dib -> Rescale($wmax, $heightimg/$wratio);
$imgwid=$wmax, $imglen=$heightimg/$wratio;}
else {$dispdib = $dib; $imgwid=$widthimg; $imglen=$heightimg;}
$hbitmap = $dispdib->ConvertToBitmap();
undef $dib;
undef $dispdib;
# Set the label and move it to center it in the space allocated.
$imglbl->SetImage($hbitmap);
$imglbl->Move(($wmax-$imgwid)/2, ($hmax-$imglen)/2);
Scott Spearman
Programmer
Pikeville Medical Center
Phone: 606-218-4660
Pager: 606-437-8542
Note: The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged material.
Any review, retransmission, dissemination or other use of, or taking any action
in reliance upon, this information by persons or entities other than the
intended recipient is prohibited. If you received this in error, please contact
the sender and delete this material from any computer.