[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Problems trying to paint semi-transparent metafile polygons.

Dave Clarkson

12/9/2004 9:39:00 PM

I am creating an app that plays a metafile on top of a image (e.g, jpg).
Specific polygons within the metafile need to have their original colour
replaced with a semi-transparent colour of my choice. I have no problem with
the colour substitution but I cannot get the transparency effect. My approach
is as follows:

1) I am using EnumerateMetafile and a callback function to identify and
process the relevant metafile polygons.

2) Prior to enumeration, I am setting up a ColorMap to specify how the
metafile polygon colours will be replaced. The new colour is constructed
using Color.FromArgb() with an Alpha value to control transparency.

3) The ColorMap is then used with SetRemapTable in an ImageAttributes object.

4) The ImageAttributes is provided to EnumerateMetafile

PlayRecord is called for the relevant polygons within the callback method.
In theory, it should render the polygon and apply the colour substitutions as
specifed by the ImageAttributes information. The colour substitution is
working fine,
BUT the new colour is rendered 100% opaque (i.e., no transparency). It does
not matter what Alpha value I use. It is behaving like the Alpha value is
ignored. Code snippets follow.

Enumeration Method snippet:

private void UserControl1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
<snip>
if ( myMetaFile != null )
{
Graphics.EnumerateMetafileProc fnCallback = new
Graphics.EnumerateMetafileProc( MetafileCallback );

ColorMap[] myColorMap = new ColorMap[1];
myColorMap[0] = new ColorMap();
myColorMap[0].OldColor = Color.White;
myColorMap[0].NewColor = Color.FromArgb(35, 0, 255, 0); // Note the Alpha
value (35)

ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetRemapTable(myColorMap);

g.EnumerateMetafile( myMetaFile,
new Rectangle( pictureLocation, pictureSize ),
fnCallback,
IntPtr.Zero,
imageAttr );
}

Callback Method snippet:

private bool MetafileCallback(
EmfPlusRecordType recordType,
int flags,
int dataSize,
IntPtr data,
PlayRecordCallback callbackData)
{
byte[] metafileRecordData = null;
if (data != IntPtr.Zero)
{
metafileRecordData = new byte[dataSize];
Marshal.Copy(data, metafileRecordData, 0, dataSize);
}

if (recordType == EmfPlusRecordType.EmfPolygon16)
{
mtfBoxB.PlayRecord( recordType, flags, dataSize, metafileRecordData );
<snip>


Any help would be appreciated.
Regards,
Dave Clarkson