I have code working now that will create a legend swatch for each of my layers, and also for each of my custom categories. The problem I'm having now is that the legend swatches have a duplicate of the image i want in the upper left of the created swatch. I've attached a couple example images to show what I mean. It happens for line types layers as well as point types.
Does anyone have any idea why this is happening? My method that creates the images is listed below.
public string CreateLegendImages(ThinkGeo.MapSuite.Core.Style style, string uVal, bool isInner)
{
GdiPlusGeoCanvas canvas = new GdiPlusGeoCanvas();
string legendBaseDir = Path.Combine(LMTO.WPF.Business.ProjectInfo.ProjectFolderPath, "LegendImage");
if (!Directory.Exists(legendBaseDir))
Directory.CreateDirectory(legendBaseDir);
string filePath = string.Format(@"{0}\{1}.jpg", legendBaseDir, uVal + ((isInner) ? "I" : "O"));
using (Bitmap bitmap = new Bitmap(20, 20))
{
//Here is the filePath of legend image, you can define it you want.
canvas.BeginDrawing(bitmap, new RectangleShape(0, bitmap.Width, bitmap.Height, 0), GeographyUnit.DecimalDegree);
if (style is CachedValueStyle)
{
PointStyle pointStyle = style as PointStyle;
pointStyle.DrawSample(canvas);
canvas.DrawScreenImageWithoutScaling(bitmap, 0, 0, DrawingLevel.LevelOne, 0, 0, 0);
// Todo:
if (!File.Exists(filePath))
bitmap.Save(filePath);
}
else if (style is PointStyle)
{
PointStyle pointStyle = style as PointStyle;
pointStyle.DrawSample(canvas);
canvas.DrawScreenImageWithoutScaling(bitmap, 0, 0, DrawingLevel.LevelOne, 0, 0, 0);
// Todo:
if (!File.Exists(filePath))
bitmap.Save(filePath);
}
else if (style is LineStyle)
{
LineStyle lineStyle = style as LineStyle;
lineStyle.DrawSample(canvas);
canvas.DrawScreenImageWithoutScaling(bitmap, 0, 0, DrawingLevel.LevelOne, 0, 0, 0);
// Todo:
if (!File.Exists(filePath))
bitmap.Save(filePath);
}
else if (style is AreaStyle)
{
AreaStyle areaStyle = style as AreaStyle;
areaStyle.DrawSample(canvas);
canvas.DrawScreenImageWithoutScaling(bitmap, 0, 0, DrawingLevel.LevelOne, 0, 0, 0);
// Todo:
if (!File.Exists(filePath))
bitmap.Save(filePath);
}
}
return filePath;
}
SemiannualI.jpg (568 Bytes)
Deep_ConcContour.shpO.jpg (164 Bytes)