Click to See Complete Forum and Search --> : Please help me, i am totaly lost with a verry simple gdi+ problem


lcprog
October 27th, 2004, 05:59 AM
Good Morning everybody. I am totally lost.
First i escuse myself for my poor english.
I have developped a greyscaling bitmap function in visual basic 6.
When i use this function on a 24 bpp bitmap, i get a good greyscaled bitmap but she's converted in 32bpp pixel format!!!!

So, i want to make pixel format convertion with gdi+. I am searching it for 2 week ago and i have not found anything...
I want to get a 8bpp pixelformat bitmap, not a 32bpp pixelformat bitmap...


if somebody can help me a little bit it will verry fantastic for me.
I am totaly lost...

Best Regards,

Loïc





my greyscale function:



Public Function SetGreyScale(nNativeImage as long) As Long


Dim nGraphics As Long
Dim nNewBmp As Long
Dim nHeight As Long
Dim nWidth As Long
Dim imgAttr As Long, clrMatrix As ColorMatrix
Dim sngContrast As Single


sngContrast = 0.35
nHeight = GetHeight
nWidth = GetWidth


clrMatrix.m(0, 0) = sngContrast: clrMatrix.m(1, 0) = sngContrast: clrMatrix.m(2, 0) = sngContrast: clrMatrix.m(3, 0) = 0: clrMatrix.m(4, 0) = 0
clrMatrix.m(0, 1) = sngContrast: clrMatrix.m(1, 1) = sngContrast: clrMatrix.m(2, 1) = sngContrast: clrMatrix.m(3, 1) = 0: clrMatrix.m(4, 1) = 0
clrMatrix.m(0, 2) = sngContrast: clrMatrix.m(1, 2) = sngContrast: clrMatrix.m(2, 2) = sngContrast: clrMatrix.m(3, 2) = 0: clrMatrix.m(4, 2) = 0
clrMatrix.m(0, 3) = 0: clrMatrix.m(1, 3) = 0: clrMatrix.m(2, 3) = 0: clrMatrix.m(3, 3) = 1: clrMatrix.m(4, 3) = 0
clrMatrix.m(0, 4) = 0: clrMatrix.m(1, 4) = 0: clrMatrix.m(2, 4) = 0: clrMatrix.m(3, 4) = 0: clrMatrix.m(4, 4) = 1


Call GdipCreateImageAttributes(imgAttr)
Call GdipSetImageAttributesColorMatrix(imgAttr, ColorAdjustTypeDefault, True, clrMatrix, ByVal 0, ColorMatrixFlagsDefault)


Call GdipGetImageGraphicsContext(nNativeImage, nGraphics)
Call GdipCreateBitmapFromGraphics(nWidth, nHeight, nGraphics, nNewBmp)
Call GdipDeleteGraphics(nGraphics) ' Cleanup so we can reuse the variable
Call GdipGetImageGraphicsContext(nNewBmp, nGraphics)
Call GdipDrawImageRectRectI(nGraphics, nNativeImage, 0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight, UnitPixel, imgAttr)
Call GdipDisposeImageAttributes(imgAttr)
GdipDisposeImage nNativeImage
nNativeImage = nNewBmp
GdipDeleteGraphics nGraphics
Call GdipDisposeImage(nNativeImage)

SetGreyScale = nNewBmp
End Function

GilC
November 29th, 2004, 05:52 AM
if you want to convert pixel format, try Bitmap.ConvertFormat

ryu
September 28th, 2005, 02:03 AM
But Bitmap::ConvertFormat() only works in GDI+ 1.1. I am using Windows XP, how can I use GDI+ 1.1 instead of GDI+ 1.0?

Thanks...

andytim
October 12th, 2005, 03:10 AM
For GDI+1.1,I think you should install the latest SDK kit (You can obatin it from MS).

Andy

---------------------------------------------------------------------------------
XD++ MFC/C++ Flow/Diagram Library (Full Visio 2003 Like,100% Source Code Kit) -- http://www.********.net