public void DrawImage(INativeImage image, int x, int y) { x -= origin.X; y -= origin.Y; // todo: allow null? X11Image x11Image = (X11Image)image; XRenderPictureAttributes attr = new XRenderPictureAttributes(); var tempPictureId = LibXRender.XRenderCreatePicture(display, x11Image.PixmapId, pictFormatPtr, 0, ref attr); try { LibXRender.XRenderComposite ( display, PictOp.PictOpOver, tempPictureId, 0, pictureId, 0, 0, 0, 0, x, y, (uint)x11Image.Width, (uint)x11Image.Height ); } finally { LibXRender.XRenderFreePicture(display, tempPictureId); } }
/// <summary> /// Draws an image. /// </summary> /// <param name="target"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <param name="nativeImage"></param> protected override void DrawImage(Target2DWrapper <Graphics> target, double left, double top, double right, double bottom, INativeImage nativeImage) { // get the image. var image = (nativeImage as NativeImage).Image; // set interpolation mode to default. Only used when displaying tiles. var previousInterpolationMode = target.Target.InterpolationMode; target.Target.InterpolationMode = InterpolationMode.Default; // draw image. double[] topleft = this.Tranform(left, top); double[] bottomright = this.Tranform(right, bottom); float x = (float)topleft[0]; float y = (float)topleft[1]; float width = (float)bottomright[0] - x; float height = (float)bottomright[1] - y; target.Target.DrawImage(image, new RectangleF(x, y, width, height)); // reset interpolation mode to default. target.Target.InterpolationMode = previousInterpolationMode; }
public void DrawImage(INativeImage image, int x, int y) { x += offset.X; y += offset.Y; // todo: allow null? Win32Image win32Image = (Win32Image)image; var bitmap = Gdi32API.CreateDIBSectionChecked(hdc, new BITMAPINFO(win32Image.Width, win32Image.Height), out IntPtr buffer); IntPtr hdcMem = IntPtr.Zero; try { Marshal.Copy(win32Image.Pixels, 0, buffer, win32Image.Pixels.Length); hdcMem = Gdi32API.CreateCompatibleDCChecked(hdc); var oldBitmap = Gdi32API.SelectObjectChecked(hdcMem, bitmap); Gdi32API.GdiAlphaBlend ( hdc, x, y, win32Image.Width, win32Image.Height, hdcMem, 0, 0, win32Image.Width, win32Image.Height, BLENDFUNCTION.SourceAlpha() ); Gdi32API.SelectObjectChecked(hdcMem, oldBitmap); } finally { Gdi32API.SafeDeleteObject(hdcMem); Gdi32API.DeleteObject(bitmap); } }
/// <summary> /// Initializes a new instance of the <see cref="OsmSharp.UI.Renderer.Scene.Scene2DPrimitives.TiltedImage2D"/> class. /// </summary> /// <param name="bounds">Bounds.</param> /// <param name="nativeImage">Image data.</param> public ImageTilted2D(RectangleF2D bounds, INativeImage nativeImage, float minZoom, float maxZoom) { _bounds = bounds; this.NativeImage = nativeImage; this.MinZoom = minZoom; this.MaxZoom = maxZoom; }
/// <summary> /// Creates a new Image2D. /// </summary> /// <param name="left"></param> /// <param name="top"></param> /// <param name="bottom"></param> /// <param name="right"></param> /// <param name="imageData"></param> /// <param name="minZoom"></param> /// <param name="maxZoom"></param> public Image2D(double left, double top, double bottom, double right, INativeImage nativeImage, float minZoom, float maxZoom) { this.NativeImage = nativeImage; this.Left = left; this.Right = right; this.Top = top; this.Bottom = bottom; this.MinZoom = minZoom; this.MaxZoom = maxZoom; }
/// <summary> /// Creates a new Image2D. /// </summary> /// <param name="left"></param> /// <param name="top"></param> /// <param name="bottom"></param> /// <param name="right"></param> /// <param name="nativeImage"></param> public Image2D(double left, double top, double bottom, double right, INativeImage nativeImage) { this.NativeImage = nativeImage; this.Left = left; this.Right = right; this.Top = top; this.Bottom = bottom; this.MinZoom = float.MinValue; this.MaxZoom = float.MaxValue; }
/// <summary> /// Draws an image. /// </summary> /// <param name="target"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <param name="nativeImage"></param> protected override void DrawImage(Target2DWrapper <RenderContext> target, double left, double top, double right, double bottom, INativeImage nativeImage) { var wpfNativeImage = nativeImage as NativeImage; if (wpfNativeImage != null) { var leftTop = Tranform(left, top); var rightBottom = Tranform(right, bottom); var width = rightBottom.X - leftTop.X; var height = rightBottom.Y - leftTop.Y; var destRect = new Rect(leftTop, new Size(width, height)); target.Render().DrawImage(destRect, wpfNativeImage.Image); } }
/// <summary> /// Release the given image. /// </summary> /// <param name="image">The image to release.</param> public override void Release(INativeImage image) { OsmSharp.Logging.Log.TraceEvent("NativeImageCache", Logging.TraceEventType.Information, "Bitmap release: {0} {1}", _unusedImages.Count, _usedImages.Count); lock (_usedImages) { // synchronize access to this cache. if (!_usedImages.Contains(image)) { // oeps, cannot release an image that is not used! OsmSharp.Logging.Log.TraceEvent("NativeImageCache", Logging.TraceEventType.Information, "Bitmap release exception: {0} {1}", _unusedImages.Count, _usedImages.Count); throw new Exception("Cannot release an unused image."); } _usedImages.Remove(image); _unusedImages.Add(image); } OsmSharp.Logging.Log.TraceEvent("NativeImageCache", Logging.TraceEventType.Information, "After bitmap release: {0} {1}", _unusedImages.Count, _usedImages.Count); }
/// <summary> /// Draws an image on the target. /// </summary> /// <param name="target"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <param name="nativeImage"></param> /// <returns>The image.</returns> protected override void DrawImage(Target2DWrapper <CGContextWrapper> target, double left, double top, double right, double bottom, INativeImage nativeImage) { // get the native image. var iosNativeImage = (nativeImage as NativeImage); // get CGImage. CGImage image = iosNativeImage.Image; var bounds = new RectangleF2D(left, bottom, (left - right), (top - bottom)); target.Target.CGContext.SetAllowsFontSubpixelQuantization(true); target.Target.CGContext.SetAllowsFontSmoothing(true); target.Target.CGContext.SetAllowsAntialiasing(true); target.Target.CGContext.SetAllowsSubpixelPositioning(true); target.Target.CGContext.SetShouldAntialias(true); PointF2D bottomLeft = new PointF2D(this.Transform(bounds.BottomLeft[0], bounds.BottomLeft[1])); PointF2D bottomRight = new PointF2D(this.Transform(bounds.BottomRight[0], bounds.BottomRight[1])); PointF2D topLeft = new PointF2D(this.Transform(bounds.TopLeft[0], bounds.TopLeft[1])); //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1])); RectangleF2D transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft), topLeft - bottomLeft); target.Target.CGContext.SaveState(); target.Target.CGContext.TranslateCTM((float)transformed.BottomLeft[0], (float)transformed.BottomLeft[1]); target.Target.CGContext.RotateCTM(-(float)((Radian)transformed.Angle).Value); target.Target.CGContext.ScaleCTM(-1, 1); // build rectangle. _rectangle.X = 0; _rectangle.Y = 0; _rectangle.Width = (float)transformed.Width; _rectangle.Height = (float)transformed.Height; target.Target.CGContext.DrawImage(_rectangle, image); target.Target.CGContext.RestoreState(); }
/// <summary> /// Draws an image on the target. /// </summary> /// <param name="target"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <param name="imageData"></param> protected abstract void DrawImage(Target2DWrapper <TTarget> target, double left, double top, double right, double bottom, INativeImage tag);
/// <summary> /// Release the given image. /// </summary> /// <param name="image">The image to release.</param> public override void Release(INativeImage image) { image.Dispose(); }
/// <summary> /// Release the image to this cache again. /// </summary> /// <param name="image"></param> public abstract void Release(INativeImage image);
public NImage LoadImageFromStream(Stream stream) { INativeImage nativeImage = nativeCodec.LoadImageFromStream(stream); return(new NImage(this, nativeImage)); }
protected override void DrawImage(Target2DWrapper <OpenGLTarget2D> target, OsmSharp.Math.Primitives.RectangleF2D bounds, INativeImage tag) { }
/// <summary> /// Draws the image. /// </summary> /// <returns>The image.</returns> /// <param name="target">Target.</param> /// <param name="bounds">Bounds.</param> /// <param name="nativeImage">Image data.</param> protected override void DrawImage(Target2DWrapper <Graphics> target, RectangleF2D bounds, INativeImage nativeImage) { }
/// <summary> /// Draws the image. /// </summary> /// <returns>The image.</returns> /// <param name="target">Target.</param> /// <param name="bounds">Bounds.</param> /// <param name="nativeImage">Image data.</param> protected override void DrawImage(Target2DWrapper <Canvas> target, RectangleF2D bounds, INativeImage nativeImage) { var nativeAndroidImage = (nativeImage as NativeImage); global::Android.Graphics.Bitmap image = nativeAndroidImage.Image; this.Transform(bounds.BottomLeft [0], bounds.BottomLeft [1], _transformed1); PointF2D bottomLeft = new PointF2D(_transformed1[0], _transformed1[1]); this.Transform(bounds.BottomRight [0], bounds.BottomRight [1], _transformed1); PointF2D bottomRight = new PointF2D(_transformed1[0], _transformed1[1]); this.Transform(bounds.TopLeft [0], bounds.TopLeft [1], _transformed1); PointF2D topLeft = new PointF2D(_transformed1[0], _transformed1[1]); //PointF2D topRight = new PointF2D(this.Tranform (bounds.TopRight [0], bounds.TopRight [1])); var transformed = new RectangleF2D(bottomLeft, bottomLeft.Distance(bottomRight), bottomLeft.Distance(topLeft), topLeft - bottomLeft); _paint.AntiAlias = true; _paint.FilterBitmap = true; target.Target.Save(); target.Target.Translate((float)transformed.BottomLeft [0], (float)transformed.BottomLeft [1]); target.Target.Rotate(-(float)((Degree)transformed.Angle).Value); if (image != null) { target.Target.DrawBitmap(image, new global::Android.Graphics.Rect(0, 0, image.Width, image.Height), new global::Android.Graphics.RectF(0, 0, (float)transformed.Width, (float)transformed.Height), _paint); } target.Target.Restore(); }
/// <summary> /// Draws an image on the target. /// </summary> /// <param name="target"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <param name="nativeImage"></param> protected override void DrawImage(Target2DWrapper <global::Android.Graphics.Canvas> target, double left, double top, double right, double bottom, INativeImage nativeImage) { var rectangle = new RectangleF2D(left, top, right - left, bottom - top); this.DrawImage(target, rectangle, nativeImage); }
/// <summary> /// Draws the image. /// </summary> /// <returns>The image.</returns> /// <param name="target">Target.</param> /// <param name="bounds">Bounds.</param> /// <param name="imageData">Image data.</param> /// <param name="tag">Tag.</param> protected abstract void DrawImage(Target2DWrapper <TTarget> target, RectangleF2D bounds, INativeImage tag);
protected override void DrawImage(Target2DWrapper <OpenGLTarget2D> target, double left, double top, double right, double bottom, INativeImage tag) { }
/// <summary> /// Draws the image. /// </summary> /// <returns>The image.</returns> /// <param name="target">Target.</param> /// <param name="bounds">Bounds.</param> /// <param name="nativeImage">Image data.</param> protected override void DrawImage(Target2DWrapper <RenderContext> target, RectangleF2D bounds, INativeImage nativeImage) { DrawImage(target, bounds.TopLeft[0], bounds.TopLeft[1], bounds.BottomRight[0], bounds.BottomRight[1], nativeImage); }
internal NImage(NImageCodec codec, INativeImage nativeImage) { Codec = codec; NativeImage = nativeImage; }