Page 1 of 1
Create or Save Image as Black and White
Posted: Tue Apr 20, 2010 5:06 pm
by Xombie
In the past I've used...
Code: Select all
TestImage = CreateImage(#PB_Any, 2550, 4200, 1)
hdc = CreateCompatibleDC_(0)
SelectObject_(hdc, ImageID(TestImage))
SetDIBColorTable_(hdc, 0, 2, @palette())
DeleteDC_(hdc) : hdc = 0
...to create a black and white image and it's worked fine. What's the recommended method for PB 4.50?
Re: Create or Save Image as Black and White
Posted: Tue Apr 20, 2010 7:09 pm
by Thorium
4.50 does not support indexed images any longer.
But it supports to save them, so i think the solution is to just use 24bit image and just use black and white, when you save it, you specify it as 1bit.
Re: Create or Save Image as Black and White
Posted: Tue Apr 20, 2010 7:35 pm
by Xombie
I'm using GDI+ to save the image (multipage TIF) so I'll dig around on that to see how to save it as bitonal.
Thanks!
Re: Create or Save Image as Black and White
Posted: Tue Apr 20, 2010 8:28 pm
by srod
You can use api to create a monochrome dibsection easily enough...
Code: Select all
hdc = CreateCompatibleDC_(0)
If hdc
With bmi.BITMAPINFO
\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
\bmiHeader\biWidth = 300
\bmiHeader\biHeight = 300
\bmiHeader\biPlanes = 1
\bmiHeader\biBitCount = 1
EndWith
hBMP = CreateDIBSection_(hdc, @bmi, #DIB_RGB_COLORS, 0, 0, 0)
If hBMP
oldimage = SelectObject_(hdc, hBMP)
Dim colors.l(1)
colors(0) = #Black
colors(1) = #White
SetDIBColorTable_(hdc, 0, 2, @Colors())
SelectObject_(hdc, oldimage)
EndIf
DeleteDC_(hdc)
EndIf
hBMP gives you an image handle which you can use in image gadgets etc.
Alternatively use CreateBitmap_() to create a monochrome ddb. This of course will have no color table.
Re: Create or Save Image as Black and White
Posted: Tue Apr 20, 2010 11:05 pm
by Fred
You can specify the 'Depth' in SaveImage() in 4.50, it should do the trick (don't use dithering if you only use 2 colors in your 24 bit image).
Re: Create or Save Image as Black and White
Posted: Wed Apr 21, 2010 4:23 pm
by Xombie
And for GDI+ I simply did the following...
Code: Select all
EncoderParameters\Count = 2
;
CopyMemory(?EncoderSaveFlag, @EncoderParameters\Parameter[0]\Guid, SizeOf(GUID))
EncoderParameters\Parameter[0]\type = 4
EncoderParameters\Parameter[0]\NumberOfValues = 1
EncoderParameters\Parameter[0]\Value = @ParameterValue
;
ColorDepth = 1
;
CopyMemory(?EncoderColorDepth, @EncoderParameters\Parameter[1]\Guid, SizeOf(GUID))
EncoderParameters\Parameter[1]\type = 4
EncoderParameters\Parameter[1]\NumberOfValues = 1
EncoderParameters\Parameter[1]\Value = @ColorDepth
Where EncoderColorDepth is...
Code: Select all
EncoderColorDepth:
Data.l $66087055
Data.w $AD66, $4C7C
Data.b $9A, $18, $38, $A2, $31, $0B, $83, $37