Hi,
I am working on the printing of my thinkgeo desktop application (which I am in the midst of converting to SDK 4 from 2.x). I am using the PrinterGeoCanvas but having problems with various custom layers which override DrawCore.
I have a SeamlessGrid class which inherits from GridFeatureLayer. Within this class I am overriding DrawCore and I'm drawing all the cells of the grid individually to a graphics object/bitmap, then setting the opacity of the bitmap, copying the bitmap to a GeoImage and finally drawing the GeoImage to screen using canvas.DrawScreenImageWithoutScaling
This code works fine when the canvas is a normal map canvas, but when it's a PrinterGeoCanvas it exhibits 2 problems.
- The DrawScreenImageWithoutScaling seems to ignore the image opacity
- The image draws in the wrong place and/or at the wrong scale
I have tried to use DrawScreenImage instead and scale the GeoImage manually but when I do this, the image isn't drawn on the printer canvas at all - I can't get DrawScreenImage to work at all with PrinterGeoCanvas. Dim w As Integer = canvas.Width
Dim h As Integer = canvas.Height
Dim bmp As New Bitmap(w, h)
Dim gr As Graphics = Graphics.FromImage(bmp)
'draw the grid here
'blah blah
Dim mstream As New MemoryStream()
gr.Dispose()
Dim bmp2 As New Bitmap(w, h)
bmp2 = SetImgOpacity(bmp, CSng(grid_opacity / 255))
bmp2.Save(mstream, System.Drawing.Imaging.ImageFormat.Png)
Dim img As New GeoImage(mstream)
If TypeOf (canvas) Is PrinterGeoCanvas Then
canvas.DrawScreenImageWithoutScaling(img, cx, cy, DrawingLevel.LevelOne, 0, 0, 0)
Else
canvas.DrawScreenImageWithoutScaling(img, cx, cy, DrawingLevel.LevelOne, 0, 0, 0)
End If
A similar problem occurs when drawing labels in a custom label class (that should draw a label just under a point shape) that overrides DrawCore:
If TypeOf (canvas) Is PrinterGeoCanvas Then
canvas.DrawTextWithWorldCoordinate(textstring, fnt, br, _
feature.GetBoundingBox.GetCenterPoint.X , _
feature.GetBoundingBox.GetCenterPoint.Y - ((fontSize + 4) _
* canvas.CurrentWorldExtent.Height / canvas.Height), _
ThinkGeo.MapSuite.Core.DrawingLevel.LabelLevel)
Else
canvas.DrawTextWithWorldCoordinate(textstring, fnt, br, _
feature.GetBoundingBox.GetCenterPoint.X, _
feature.GetBoundingBox.GetCenterPoint.Y - ((fontSize + 4) _
* canvas.CurrentWorldExtent.Height / canvas.Height), _
ThinkGeo.MapSuite.Core.DrawingLevel.LabelLevel)
End If
The PrinterGeoCanvas again draws in the wrong place. I have tried playing around with the printer margins etc but to no effect.
Am I using PrinterGeoCanvas wrong somehow? Are these known limitations/problems with the class?
Just as an aside, the grid drawing works fine using the PdfGeoCanvas.
Thanks,
Jeremy