Select to view content in your preferred language

GDI+ Smooth Edge Draw Issue

3812
10
07-11-2010 09:37 AM
by Anonymous User
Not applicable
Original User: dberry911

I am using VS2005 VB.NET with ArcObjects V9.3.1.

I am using GDI+ to DrawImage, DrawString, DrawEllipse as part of an AVL Tracking Layer(non-dynamic map).

Resulting images, text, and ellipsis are not drawn smooth, they appear as having rough edges.

Using the same code in a test application results in all images & text with smooth edges.

The GDI+ MeasureString method calculates inaccurate values, but in the test application calculations are correct.

When DrawText is used with a background the text has smooth edges, but if drawn directly on the MapControl the text has rough edges.

I am setting the SmoothingMode of the graphics to Antialias and have tried every other combination without success.

Attached are examples of rough & smooth edges of an ellipse.



Anyone else see this same issue?

Suggestions & insights appreciated.

Regards,
Dennis
0 Kudos
10 Replies
by Anonymous User
Not applicable
Original User: kirkktx

Post your code showing how you are calling GDI+.
0 Kudos
DennisBerry
Emerging Contributor
Kirk,

In essence here is the code that I use to draw a circle.

        Dim sdpPen As Pen

        sdpPen = New Pen(Brushes.Yellow)
        sdpPen.Width = 10.0F

        e.Graphics.DrawEllipse(sdpPen, New Rectangle(200, 100, 80, 80))

        sdpPen.Dispose()

It's really pretty simple.

See what you think,
Dennis
0 Kudos
by Anonymous User
Not applicable
Original User: kirkktx

The code below works for me, clicking on the mapcontrol toggles antialiasing.


private SmoothingMode m_mode = SmoothingMode.AntiAlias;
public MapForm1()
{
    InitializeComponent();
}

private void axMapControl1_OnAfterScreenDraw(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterScreenDrawEvent e)
{
    Graphics g = Graphics.FromHdc(new IntPtr(e.hdc));
    DrawEllipse(g);
    g.Dispose();
}
private void DrawEllipse(Graphics g)
{
    g.SmoothingMode = m_mode;
    Pen sdPen = new Pen(Brushes.Red, (float)10.0);
    g.DrawEllipse(sdPen, new Rectangle(100, 100, 200, 200));
    sdPen.Dispose();
}

private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
    if (m_mode == SmoothingMode.AntiAlias)
        m_mode = SmoothingMode.HighSpeed;
    else
        m_mode = SmoothingMode.AntiAlias;
    axMapControl1.Refresh();
}
0 Kudos
DennisBerry
Emerging Contributor
Kirk,

The code I use is the same as the example you provided, but as you can see by the attached picture that drawn according to your example are smooth and mine is rough.

The difference is that your example draws in the MapControl's OnAfterScreenDraw, whereas I am doing mine in the Draw Event of a custom IMarkerSymbol Class, which inherits ISymbol, that is invoked from the Draw Event of an inherited CustomBaseLayer that inherits ILayer.

I wonder if there is some property that needs to be set somewhere along the way.

Thanks,
Dennis
0 Kudos
by Anonymous User
Not applicable
Original User: kirkktx

Did you try setting ILayer.Cached = true for your custom layer before adding it to the map?
0 Kudos
DennisBerry
Emerging Contributor
Yes, I set Cached=True prior to adding the layer to the MapControl.

Seems to me there is something about the layer that interferes with GDI+.  Everything that is drawn on it has rough edges, including icons and text.

I just applied 9.3.1 SP2, but that had no effect.

Anything else you might suggest?

Thanks,
Dennis
0 Kudos
by Anonymous User
Not applicable
Original User: kirkktx

How are you creating your graphics object?  Are you creating it from the hDC passed to ILayer.Draw?
0 Kudos
DennisBerry
Emerging Contributor
My ILayer.Draw has the following basic logic:

Display.StartDrawing(Display.hDC, CShort(ESRI.ArcGIS.Display.esriScreenCache.esriAllScreenCaches))

For Each Item to Draw
    Display.SetSymbol(MyCustomIMarker)
    Display.DrawPoint(MyPoint)
Next

Display.FinishDrawing()


The Draw is not done here but in the CustomMarker Class.  The SetupDC Event is passed the hDC from which the Graphics Object is created.

Private Sub SetupDC(ByVal hdc As Integer, ByVal aoDisplayTrans As ESRI.ArcGIS.Geometry.ITransformation) Implements ESRI.ArcGIS.Display.ISymbol.SetupDC

     ' create graphics
    myGraphics = Graphics.FromHdc(hdc)
    myGraphics.SmoothingMode = SmoothingMode.AntiAlias
    myGraphics.InterpolationMode = InterpolationMode.HighQualityBilinear

End Sub

The IMarker.Draw Event then uses the above Graphics Object.

It doesn't matter where along the event path the drawing is done they all appear with rough edges as well as labels that have rough edges.
0 Kudos
by Anonymous User
Not applicable
Original User: kirkktx

In your implementation of ILayer.Draw, try commenting out the startdrawing and finishdrawing calls.

I think the map calls these methods before/after calling ILayer.Draw.
0 Kudos