using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Media; using System.Windows.Interop; namespace CSHowDoISamples { public partial class DisplayASimpleMap : UserControl { public DisplayASimpleMap() { InitializeComponent(); } int rotateAngle = 50; float YourLat = 0f; float YourLong = 0f; string YourBitmapPath = .....; private void WpfMap_Loaded(object sender, RoutedEventArgs e) { Map1.MapUnit = GeographyUnit.DecimalDegree; Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9); SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay(); markerOverlay.Drawing += new EventHandler(markerOverlay_Drawing); markerOverlay.Drawn += new EventHandler(markerOverlay_Drawn); Random rand = new Random(); stopWatch.Start(); for (int i = 0; i < 1000; i++) { rotateAngle = rand.Next(0, 360); Marker marker = new Marker(rand.Next(-180, 180), rand.Next(-90, 90)); marker.Width = 20; marker.Height = 34; marker.YOffset = -17; if (i == 9881) { i = 9881; } Bitmap bitmap = new Bitmap(YourBitmapPath); IntPtr a = KiRotate(bitmap, (int)rotateAngle).GetHbitmap(); marker.ImageSource = Imaging.CreateBitmapSourceFromHBitmap(a, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); markerOverlay.Markers.Add(marker); } stopWatch.Stop(); var b = stopWatch.Elapsed.TotalMilliseconds; Map1.Overlays.Add("MarkerOverlay", markerOverlay); Map1.Refresh(); } void markerOverlay_Drawn(object sender, DrawnOverlayEventArgs e) { stopWatch.Stop(); var a = stopWatch.Elapsed.TotalMilliseconds; } System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); void markerOverlay_Drawing(object sender, DrawingOverlayEventArgs e) { stopWatch.Restart(); } public static Bitmap KiRotate(Bitmap bmp, float angle) { angle = angle % 360; if (angle > 180) angle -= 360; System.Drawing.Imaging.PixelFormat pf = default(System.Drawing.Imaging.PixelFormat); pf = bmp.PixelFormat; float sin = (float)Math.Abs(Math.Sin(angle * Math.PI / 180.0)); // this function takes radians float cos = (float)Math.Abs(Math.Cos(angle * Math.PI / 180.0)); // this one too float newImgWidth = sin * bmp.Height + cos * bmp.Width; float newImgHeight = sin * bmp.Width + cos * bmp.Height; float originX = 0f; float originY = 0f; if (angle > 0) { if (angle <= 90) originX = sin * bmp.Height; else { originX = newImgWidth; originY = newImgHeight - sin * bmp.Width; } } else { if (angle >= -90) originY = sin * bmp.Width; else { originX = newImgWidth - sin * bmp.Height; originY = newImgHeight; } } Bitmap newImg = new Bitmap((int)newImgWidth, (int)newImgHeight, pf); Graphics g = Graphics.FromImage(newImg); g.TranslateTransform(originX, originY); // offset the origin to our calculated values g.RotateTransform(angle); // set up rotate g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.DrawImageUnscaled(bmp, 0, 0); g.Dispose(); return newImg; } } }