I hope someone can help with this problem.
My program creates an image using black and white colors only. Now I want to save as grayscale bmp, i.e. with 8 bit color depth. Whatever I do, the file will be saved as bilevel, with 1 bit colordepth only.
(The target application will not accept this file.)
The sequence is:
-take a grayscale image as input
-apply "threshold" to make it black and white
-save
Thanks for helping!
Christian
Need to save monochrome image as grayscale bmp
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Need to save monochrome image as grayscale bmp
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
Re: Need to save monochrome image as grayscale bmp
I tried this already, it doesn't seem to be that easy. Here is my sample script.
The call of Set() doesnt have any effect, the files threshold.bmp and set_depth_colors.bmp are identical.
Only after calling Quantize() at least the colorspace changes , the color depth does not.
Christian
Code: Select all
use Image::Magick;
my $img = Image::Magick -> new();
$img -> Read("original.bmp"); # has 8 bits
print "spa: ", $img ->Get("colorspace"), "\n"; # returns RGB
print "col: ", $img ->Get("colors"), "\n"; # returns 243
print "typ: ", $img ->Get("type"), "\n"; # returns Grayscale
print "dep: ", $img ->Get("depth"), "\n"; # returns 8
$img->Threshold("50%");
print "spa: ", $img ->Get("colorspace"), "\n"; # returns RGB
print "col: ", $img ->Get("colors"), "\n"; # returns 2
print "typ: ", $img ->Get("type"), "\n"; # returns Bilevel
print "dep: ", $img ->Get("depth"), "\n"; # returns 1
$img -> Write(filename => "threshold.bmp"); # has 24 bits
$img->Set(depth => 8, colors => 8, type => "Grayscale");
print "spa: ", $img ->Get("colorspace"), "\n"; # returns RGB
print "col: ", $img ->Get("colors"), "\n"; # returns 2
print "typ: ", $img ->Get("type"), "\n"; # returns Bilevel
print "dep: ", $img ->Get("depth"), "\n"; # returns 1
$img -> Write(filename => "set_depth_colors.bmp"); # has 24 bits
$img -> Quantize();
print "spa: ", $img ->Get("colorspace"), "\n"; #returns Gray
print "col: ", $img ->Get("colors"), "\n"; # returns 2
print "typ: ", $img ->Get("type"), "\n"; # returns Bilevel
print "dep: ", $img ->Get("depth"), "\n"; # returns 1
$img -> Write(filename => "quantize.bmp"); # has 1 bit
Only after calling Quantize() at least the colorspace changes , the color depth does not.
Christian
Re: Need to save monochrome image as grayscale bmp
To close this topic:
I am applying a silly workaround now: save a temporary file as tif, then open it again and save as bmp. No clue why this works, but it does.
Christian
I am applying a silly workaround now: save a temporary file as tif, then open it again and save as bmp. No clue why this works, but it does.
Christian