COLORMAP with more than one entry (GDI+)

borax
02-17-2005, 09:50 AM
Is it possible to have either an array of COLORMAPs or a COLORMAP with an array of oldcolor-newcolor enties? I need to replace serveral colors. This work fine with subsequent calls to the ReplaceColor Function, but is surely not the right way to do it...

Code snip (is a modified function of the "MakeTransparent" funktion in cBitmap from OnErrOr)

Public Function ReplaceColor(ByVal OldColor As Long, ByVal NewColor As Long) As Long
Dim bmp As cBitmap
Dim gfx As cGraphics
Set bmp = New cBitmap
Set gfx = New cGraphics
Dim rc As RECT
Dim lAttrib As Long
Dim ReMapTab As COLORMAP
Dim lTmpHandle As Long

ReMapTab.NewColor = NewColor
ReMapTab.OldColor = OldColor

If bmp.CreateFromScan0(m_lWidth, m_lHeight, 0, PixelFormat32bppARGB, 0) = Ok Then
If gfx.GetGraphicsContext(bmp.Handle) = Ok Then
If gfx.Clear = Ok Then
rc.Right = m_lWidth
rc.Bottom = m_lHeight

If GdipCreateImageAttributes(lAttrib) = Ok Then
If GdipSetImageAttributesRemapTable(lAttrib, ColorAdjustTypeDefault, 1, 2, ReMapTab) = Ok Then
If gfx.DrawImageRectRectIAttr(bitmap, 0, 0, m_lWidth, m_lHeight, 0, 0, m_lWidth, m_lHeight, lAttrib) = Ok Then
...


I have tried with:
Dim ReMapTab(0 to 10) As COLORMAP
but this gives me a type mismatch error?!

borax
02-24-2005, 02:16 PM
No ideas, not possible or wrong question?

OnErr0r
02-24-2005, 05:50 PM
Function GdipSetImageAttributesRemapTable(imageattr As Long, type As ColorAdjustType, enableFlag As Long, mapSize As Long, map As COLORMAP) As Long


The last parameter is a COLORMAP struct. You are passing a SAFEARRAY. Passing the first item in the array will pass the address of the COLORMAP array.

borax
02-25-2005, 02:39 AM
THX! Works great!
I didn't know that it is a SAFEARRAY...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum