private static void PreviewImageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { FontPicker currentInstance = (FontPicker)sender; int selectedCharIndex = currentInstance.SelectedCharacterIndex; PointStyle pointStyle = new PointStyle( new GeoFont(currentInstance.SelectedFontFamily.Source, defaultFontSize, currentInstance.SelectedFontStyle), currentInstance.SelectedCharacterIndex, new GeoSolidBrush(GeoColor.StandardColors.Black)); System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(defaultPreviewSize, defaultPreviewSize); var geoCanvas = new PlatformGeoCanvas(); try { geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-90, 90, 90, -90), GeographyUnit.DecimalDegree); pointStyle.DrawSample(geoCanvas); geoCanvas.EndDrawing(); MemoryStream streamSource = new MemoryStream(); nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png); BitmapImage imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = streamSource; imageSource.EndInit(); currentInstance.PreviewImage = imageSource; } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { nativeImage.Dispose(); } }
private static void DrawDotDensityStyle(PointStyle pointStyle, PlatformGeoCanvas canvas, DrawingRectangleF drawingRectangleF) { if (pointStyle == null) { return; } var tmpSymbolSize = pointStyle.SymbolSize; var tmpSymbolPenWidth = pointStyle.SymbolPen.Width; var tmpFontSize = pointStyle.CharacterFont.Size; Bitmap originalBitmap = null; Bitmap newBitmap = null; try { var customerSymbolStyle = pointStyle as SymbolPointStyle; if (customerSymbolStyle != null) { originalBitmap = canvas.ToNativeImage(customerSymbolStyle.Image) as Bitmap; newBitmap = new Bitmap(originalBitmap, 9, 9); customerSymbolStyle.Image = canvas.ToGeoImage(newBitmap); } else { pointStyle.SymbolSize = 3; pointStyle.SymbolPen.Width = 1; pointStyle.CharacterFont = new GeoFont(pointStyle.CharacterFont.FontName, 6, pointStyle.CharacterFont.Style); } var halfWidth = drawingRectangleF.Width * 0.5f; var halfHeight = drawingRectangleF.Height * 0.5f; float[] centersX = new float[7]; float[] centersY = new float[7]; centersX[0] = halfWidth * 0.5f - 1; centersY[0] = halfHeight * 0.5f - 1; centersX[1] = centersX[0] + 2; centersY[1] = centersY[0] + 2; centersX[2] = halfWidth; centersY[2] = halfHeight; centersX[3] = halfWidth + halfWidth * 0.5f; centersY[3] = halfHeight; centersX[4] = halfWidth + halfWidth * 0.5f; centersY[4] = halfHeight + halfHeight * 0.5f; centersX[5] = centersX[4] - 1; centersY[5] = centersY[4] - 1; centersX[6] = centersX[4] + 1; centersY[6] = centersY[4] + 1; for (int i = 0; i < 7; i++) { float centerX = centersX[i]; float centerY = centersY[i]; if (pointStyle != null) { pointStyle.DrawSample(canvas, new DrawingRectangleF(centerX, centerY, 11, 11)); } } if (originalBitmap != null) { customerSymbolStyle.Image = canvas.ToGeoImage(originalBitmap); } else { pointStyle.SymbolSize = tmpSymbolSize; pointStyle.SymbolPen.Width = tmpSymbolPenWidth; pointStyle.CharacterFont = new GeoFont(pointStyle.CharacterFont.FontName, tmpFontSize, pointStyle.CharacterFont.Style); } } finally { if (originalBitmap != null) { originalBitmap.Dispose(); } if (newBitmap != null) { newBitmap.Dispose(); } } }