I have a need to save a picture as a monochrome bmp. I know how to SaveAsWindowsBMP, but this will not work as the packaging printer I am trying to create the BMP for will only accept a monochrome bmp. Any ideas or help with this would be great.
[code]Function ToBlackAndWhite(bmp as picture) As picture
For x as integer = 0 To bmp.Width
For y as integer = 0 To bmp.Height
bmp.RGBSurface.Pixel(x,y) = RGB((bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3, _
(bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3, _
(bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3)
Next y
Next x
Whatever the method used to convert the picture and the bit depth of it, the major hurdle will be saving the picture to file. Xojo saves BMP in RGB format only. So if the file format required is the uncompressed bitmap known as BW that was used by early versions of Windows, it will not be possible with simple Xojo code.
Some printers require 16 color (4 bit ) monochrome BMP. I looked in the Microsoft forums and this format seems impossible to generate with current versions of their software. This may require creating your own method for saving.
I have to agree with Michel here, I think the printer may actually want the BMP data to formatted in a very specific way. Thankfully the BMP format is not that complicated, but it may mean that you’ll need to manually generate a BMP file.
In regards to converting a picture to greyscale, my personal favorite method is CIE*Lab or a technique to replicate Infra-red images.
[quote=142049:@Michel Bujardet][code]Function ToBlackAndWhite(bmp as picture) As picture
For x as integer = 0 To bmp.Width
For y as integer = 0 To bmp.Height
bmp.RGBSurface.Pixel(x,y) = RGB((bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3, _
(bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3, _
(bmp.RGBSurface.Pixel(x, y).red + bmp.RGBSurface.Pixel(x, y).Green + bmp.RGBSurface.Pixel(x, y).Blue) / 3)
Next y
Next x
and, as the percentages in that note do not actually add up to 100%, I use:-
RED 30.0 %
GREEN 59.0 %
BLUE 11.0 %[/quote]
You are right. For a photographic usage, the human perception of colors must be taken into account so the human response curve to the different light wave length can be reproduced. Human perception is most sensitive to green. This is the reason behind the creation of black and white panchromatic films Panchromatic film - Wikipedia
Indeed it does not hurt.
The issue here is much less the perfectible quality of colors interpretation than the need to generate a file compatible with that particular printer.
An RGB BMP containing a combinations of color rendering as levels of grey is not the same thing as a true monochrome file format. Same thing not long ago when I needed BMP in 256 indexed colors that neither Xojo nor MBS could do.
Taken from Wikipedia :
As it stands, chances are unfortunately that the current RGB BMP file format used by Xojo will not do.
[quote=142141:@Michel Bujardet]
As it stands, chances are unfortunately that the current RGB BMP file format used by Xojo will not do.[/quote]
Is there any format that can save Picture to greyscale or bitmap file in Xojo?
I have been searching and reading, but this is still unclear. Are all Picture file formats 24bit (I can find no info on how using SaveAsGif, if it is even working…)?
I am saving a bunch of A4 page size monochrome images to disk (in 600dpi, roughly 4000x7000 pixels), for later manipulation. SaveAsPNG takes about 3 seconds to save for each page, jpeg slightly less and that is a bit to slow to be comfortable when writing many of them. BMP is the fastest I can make work, but as it saves in 24bit, the filesize is huge, about 100MB each, which I don’t like. As I only use 1bit data it is quite silly to waste time and space writing 24 bit files…
Do I have to try writing the monocrome data to the files myself?
(Uncompressed gif:s seems doable. Maybe. BMP, not so easy…)
[quote=160912:@Roger Jönsson]Is there any format that can save Picture to greyscale or bitmap file in Xojo?
I have been searching and reading, but this is still unclear. Are all Picture file formats 24bit (I can find no info on how using SaveAsGif, if it is even working…)?
I am saving a bunch of A4 page size monochrome images to disk (in 600dpi, roughly 4000x7000 pixels), for later manipulation. SaveAsPNG takes about 3 seconds to save for each page, jpeg slightly less and that is a bit to slow to be comfortable when writing many of them. BMP is the fastest I can make work, but as it saves in 24bit, the filesize is huge, about 100MB each, which I don’t like. As I only use 1bit data it is quite silly to waste time and space writing 24 bit files…
Do I have to try writing the monocrome data to the files myself?
(Uncompressed gif:s seems doable. Maybe. BMP, not so easy…)
I am on OS X. What to do?[/quote]
Xojo does not know how to save BMP in anything but 24 bit. Monochome and indexed color is not available.
The most compact, therefore probably fastest one, is GIF. But you will have to remove color information yourself. The method I suggested above is the simplest.
I use sips in AppleScript to make grayscale Pictures,
try
set targetfolder to "/Volumes/Axel_1/GrayPics/" -- your folder here
set theImage to (choose file) as text
set AppleScript's text item delimiters to ":"
set filename to last text item of theImage
set AppleScript's text item delimiters to "."
set extension to last text item of filename
set filename to first text item of filename
set theImage to quoted form of POSIX path of theImage
set cmd to "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic Gray Profile.icc' " & " " & theImage & " -o '" & targetfolder & filename & "_grey." & extension & "'"
do shell script cmd
on error errorMessage number errorNumber
display dialog errorMessage
end try
But, if I understand it right, I have to write the file do disk first?
I cant read the original image that from memory without saving a BMP or other file format? -Then it would not save any time. Maybe writing BMP to a ramdisk could speed it up, though.
[quote=160929:@Roger Jönsson]But, if I understand it right, I have to write the file do disk first?
I cant read the original image that from memory without saving a BMP or other file format? -Then it would not save any time. Maybe writing BMP to a ramdisk could speed it up, though.[/quote]
Thanks,
-I will, tonight (after work).
Don’t I need to set pallet info for the gif or is Xojo automatically making a suitable pallet from the data passed?
here is a version with multiple selection, try how fast it works.
I usually use the built-in OS X tools because the picture quality is better than in Xojo
try
set targetfolder to "/Volumes/Axel_1/GrayPics/" -- your folder here
set theImage to (choose file with multiple selections allowed)
repeat with i from 1 to the count of theImage
set this_item to item i of theImage
set this_item to this_item as text
set AppleScript's text item delimiters to ":"
set filename to last text item of this_item
set AppleScript's text item delimiters to "."
set extension to last text item of filename
set filename to first text item of filename
set this_item to quoted form of POSIX path of this_item
set cmd to "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic Gray Profile.icc' " & " " & this_item & " -o '" & targetfolder & filename & "_grey." & extension & "'"
do shell script cmd
end repeat
on error errorMessage number errorNumber
display dialog errorMessage
end try
[quote=160934:@Roger Jönsson]Thanks,
-I will, tonight (after work).
Don’t I need to set pallet info for the gif or is Xojo automatically making a suitable pallet from the data passed?
You’re on OS X, that’s always a good start Secondly, Xojo uses CGImages (internally) and these are compatible with CGImageDestination, which will allow you to create images in many formats, with all kinds of goodness.
Now the not so good news.
If you’re not familiar with it, it can be difficult to understand and get it to work correctly, especially if you want to save Greyscale images. MBS & MacOSLib have the functions available for you.
I feel guilty launching you into the deep end, but I don’t have the time to write a full blown tutorial on how to at the moment. Hopefully a nudge in the right direction will help.