Lars,
This is a bit tricky and depending on your code it could be accomplished using a few different techniques. The one thing to consider is the effect that you want in the end. It is a different result if all of the polygons styles you draw are transparent and then composed versus drawing them as solids first then making the final result transparent.
One way I might accomplish this is inside of the highest level style before the big loop where you go through all the features create a custom GeoCanvas that inherits from the GdiPlusGeoCanvas. Inside your custom geocanvas you override the core methods for drawing that takes the GeoColor. Inside the overload you clone the geocolor and change the alpha of it then call into the base function to do all the work. You pass this geocanvas into the lower level classes so they draw on this. After all of the drawing you call the EndDrawing on the GeoCanvas and then you superimpose the bitmap of the styles that just drew onto the regular geocanvas. Just an idea.
Another way would be to modify all of your lower level classes to take a master transparency value and they use that to tweak the geocolor when they go to draw. This might be a bit time consuming.
Included below is some sample code of the first way. I ran it and it seems to do what I want as long as the sub styles all use the temp canvas to draw everything will be transparent. I hope you can see my meaning. I originally wrote it in CSharp, included as well as a vb.net translation.
David
Public Class TransparentStyle
Inherits ThinkGeo.MapSuite.Core.Style
Protected Overrides Sub DrawCore(features As System.Collections.Generic.IEnumerable(Of Feature), canvas As GeoCanvas, labelsInThisLayer As Collection(Of SimpleCandidate), labelsInAllLayers As Collection(Of SimpleCandidate))
Dim tempCanvas As New TransparentGdiPlusGeoCanvas()
Dim transparentBitmap As Bitmap = Nothing
Dim returnStream As Stream = Nothing
Dim image As GeoImage = Nothing
Try
transparentBitmap = New Bitmap(CInt(canvas.Width), CInt(canvas.Height), PixelFormat.Format32bppPArgb)
tempCanvas.BeginDrawing(transparentBitmap, canvas.CurrentWorldExtent, canvas.MapUnit)
Dim areaStyle As New AreaStyle(New GeoSolidBrush(GeoColor.StandardColors.Red))
areaStyle.Draw(features, tempCanvas, labelsInThisLayer, labelsInAllLayers)
tempCanvas.EndDrawing()
returnStream = New MemoryStream()
transparentBitmap.Save(returnStream, ImageFormat.Png)
returnStream.Seek(0, SeekOrigin.Begin)
image = New GeoImage(returnStream)
canvas.DrawScreenImageWithoutScaling(image, canvas.Width / 2, canvas.Height / 2, DrawingLevel.LevelOne, 0, 0, _
0)
Finally
If transparentBitmap IsNot Nothing Then
transparentBitmap.Dispose()
End If
If returnStream IsNot Nothing Then
returnStream.Dispose()
End If
If image IsNot Nothing Then
image.Dispose()
End If
End Try
End Sub
End Class
Public Class TransparentGdiPlusGeoCanvas
Inherits GdiPlusGeoCanvas
Protected Overrides Sub DrawAreaCore(screenPoints As IEnumerable(Of ScreenPointF()), outlinePen As GeoPen, fillBrush As GeoBrush, drawingLevel As DrawingLevel, xOffset As Single, yOffset As Single, _
penBrushDrawingOrder As PenBrushDrawingOrder)
If outlinePen IsNot Nothing Then
outlinePen.Color = New GeoColor(100, outlinePen.Color.RedComponent, outlinePen.Color.GreenComponent, outlinePen.Color.BlueComponent)
End If
If TypeOf fillBrush Is GeoSolidBrush Then
Dim castedFillBrush As GeoSolidBrush = DirectCast(fillBrush, GeoSolidBrush)
castedFillBrush.Color = New GeoColor(100, castedFillBrush.Color.RedComponent, castedFillBrush.Color.GreenComponent, castedFillBrush.Color.BlueComponent)
End If
' Handle the other brushes
MyBase.DrawAreaCore(screenPoints, outlinePen, fillBrush, drawingLevel, xOffset, yOffset, _
penBrushDrawingOrder)
End Sub
Protected Overrides Sub DrawEllipseCore(screenPoint As ScreenPointF, width As Single, height As Single, outlinePen As GeoPen, fillBrush As GeoBrush, drawingLevel As DrawingLevel, _
xOffset As Single, yOffset As Single, penBrushDrawingOrder As PenBrushDrawingOrder)
If outlinePen IsNot Nothing Then
outlinePen.Color = New GeoColor(100, outlinePen.Color.RedComponent, outlinePen.Color.GreenComponent, outlinePen.Color.BlueComponent)
End If
If TypeOf fillBrush Is GeoSolidBrush Then
Dim castedFillBrush As GeoSolidBrush = DirectCast(fillBrush, GeoSolidBrush)
castedFillBrush.Color = New GeoColor(100, castedFillBrush.Color.RedComponent, castedFillBrush.Color.GreenComponent, castedFillBrush.Color.BlueComponent)
End If
' Handle the other brushes
MyBase.DrawEllipseCore(screenPoint, width, height, outlinePen, fillBrush, drawingLevel, _
xOffset, yOffset, penBrushDrawingOrder)
End Sub
Protected Overrides Sub DrawLineCore(screenPoints As IEnumerable(Of ScreenPointF), linePen As GeoPen, drawingLevel As DrawingLevel, xOffset As Single, yOffset As Single)
linePen.Color = New GeoColor(100, linePen.Color.RedComponent, linePen.Color.GreenComponent, linePen.Color.BlueComponent)
MyBase.DrawLineCore(screenPoints, linePen, drawingLevel, xOffset, yOffset)
End Sub
End Class
public class TransparentStyle : ThinkGeo.MapSuite.Core.Style
{
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
TransparentGdiPlusGeoCanvas tempCanvas = new TransparentGdiPlusGeoCanvas();
Bitmap transparentBitmap = null;
Stream returnStream = null;
GeoImage image = null;
try
{
transparentBitmap = new Bitmap((int)canvas.Width, (int)canvas.Height, PixelFormat.Format32bppPArgb);
tempCanvas.BeginDrawing(transparentBitmap, canvas.CurrentWorldExtent, canvas.MapUnit);
AreaStyle areaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.Red));
areaStyle.Draw(features, tempCanvas, labelsInThisLayer, labelsInAllLayers);
tempCanvas.EndDrawing();
returnStream = new MemoryStream();
transparentBitmap.Save(returnStream, ImageFormat.Png);
returnStream.Seek(0, SeekOrigin.Begin);
image = new GeoImage(returnStream);
canvas.DrawScreenImageWithoutScaling(image, canvas.Width / 2, canvas.Height / 2, DrawingLevel.LevelOne, 0, 0, 0);
}
finally
{
if (transparentBitmap != null) { transparentBitmap.Dispose(); }
if (returnStream != null) { returnStream.Dispose(); }
if (image != null) { image.Dispose(); }
}
}
}
public class TransparentGdiPlusGeoCanvas : GdiPlusGeoCanvas
{
protected override void DrawAreaCore(IEnumerable<ScreenPointF[]> screenPoints, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
{
if (outlinePen != null)
outlinePen.Color = new GeoColor(100, outlinePen.Color.RedComponent, outlinePen.Color.GreenComponent, outlinePen.Color.BlueComponent);
if (fillBrush is GeoSolidBrush)
{
GeoSolidBrush castedFillBrush = (GeoSolidBrush)fillBrush;
castedFillBrush.Color = new GeoColor(100, castedFillBrush.Color.RedComponent, castedFillBrush.Color.GreenComponent, castedFillBrush.Color.BlueComponent);
}
// Handle the other brushes
base.DrawAreaCore(screenPoints, outlinePen, fillBrush, drawingLevel, xOffset, yOffset, penBrushDrawingOrder);
}
protected override void DrawEllipseCore(ScreenPointF screenPoint, float width, float height, GeoPen outlinePen, GeoBrush fillBrush, DrawingLevel drawingLevel, float xOffset, float yOffset, PenBrushDrawingOrder penBrushDrawingOrder)
{
if (outlinePen != null)
outlinePen.Color = new GeoColor(100, outlinePen.Color.RedComponent, outlinePen.Color.GreenComponent, outlinePen.Color.BlueComponent);
if (fillBrush is GeoSolidBrush)
{
GeoSolidBrush castedFillBrush = (GeoSolidBrush)fillBrush;
castedFillBrush.Color = new GeoColor(100, castedFillBrush.Color.RedComponent, castedFillBrush.Color.GreenComponent, castedFillBrush.Color.BlueComponent);
}
// Handle the other brushes
base.DrawEllipseCore(screenPoint, width, height, outlinePen, fillBrush, drawingLevel, xOffset, yOffset, penBrushDrawingOrder);
}
protected override void DrawLineCore(IEnumerable<ScreenPointF> screenPoints, GeoPen linePen, DrawingLevel drawingLevel, float xOffset, float yOffset)
{
linePen.Color = new GeoColor(100, linePen.Color.RedComponent, linePen.Color.GreenComponent, linePen.Color.BlueComponent);
base.DrawLineCore(screenPoints, linePen, drawingLevel, xOffset, yOffset);
}
}