/// <summary> /// Draws a clipped image. /// </summary> /// <param name="rc">The render context.</param> /// <param name="clippingRectangle">The clipping rectangle.</param> /// <param name="source">The source.</param> /// <param name="x">The destination X position.</param> /// <param name="y">The destination Y position.</param> /// <param name="w">The width.</param> /// <param name="h">The height.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">interpolate if set to <c>true</c>.</param> public static void DrawClippedImage( this IRenderContext rc, OxyRect clippingRectangle, OxyImage source, double x, double y, double w, double h, double opacity, bool interpolate) { if (x > clippingRectangle.Right || x + w < clippingRectangle.Left || y > clippingRectangle.Bottom || y + h < clippingRectangle.Top) { return; } if (rc.SetClip(clippingRectangle)) { // The render context supports clipping, then we can draw the whole image rc.DrawImage(source, x, y, w, h, opacity, interpolate); rc.ResetClip(); return; } // Fint the positions of the clipping rectangle normalized to image coordinates (0,1) var i0 = (clippingRectangle.Left - x) / w; var i1 = (clippingRectangle.Right - x) / w; var j0 = (clippingRectangle.Top - y) / h; var j1 = (clippingRectangle.Bottom - y) / h; // Find the origin of the clipped source rectangle var srcx = i0 < 0 ? 0u : i0 * source.Width; var srcy = j0 < 0 ? 0u : j0 * source.Height; srcx = (int)Math.Ceiling(srcx); srcy = (int)Math.Ceiling(srcy); // Find the size of the clipped source rectangle var srcw = i1 > 1 ? source.Width - srcx : (i1 * source.Width) - srcx; var srch = j1 > 1 ? source.Height - srcy : (j1 * source.Height) - srcy; srcw = (int)srcw; srch = (int)srch; if ((int)srcw <= 0 || (int)srch <= 0) { return; } // The clipped destination rectangle var destx = i0 < 0 ? x : x + (srcx / source.Width * w); var desty = j0 < 0 ? y : y + (srcy / source.Height * h); var destw = w * srcw / source.Width; var desth = h * srch / source.Height; rc.DrawImage(source, srcx, srcy, srcw, srch, destx, desty, destw, desth, opacity, interpolate); }
/// <summary> /// Creates an image from 32-bit <c>true</c>-color pixels. /// </summary> /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param> /// <param name="format">The image format.</param> /// <param name="encoderOptions">The encoder options.</param> /// <returns>An <see cref="OxyImage" /></returns> public static OxyImage Create(OxyColor[,] pixels, ImageFormat format, ImageEncoderOptions encoderOptions = null) { var encoder = GetEncoder(format, encoderOptions); var image = new OxyImage(encoder.Encode(pixels)); // TODO: remove when PNG decoder is implemented image.pixels = pixels; return(image); }
/// <summary> /// Draws the specified image. /// </summary> /// <param name="rc">The render context.</param> /// <param name="image">The image.</param> /// <param name="x">The destination X position.</param> /// <param name="y">The destination Y position.</param> /// <param name="w">The width.</param> /// <param name="h">The height.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate the image if set to <c>true</c>.</param> public static void DrawImage( this IRenderContext rc, OxyImage image, double x, double y, double w, double h, double opacity, bool interpolate) { rc.DrawImage(image, 0, 0, image.Width, image.Height, x, y, w, h, opacity, interpolate); }
public override void DrawImage(OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) { Debug.Assert(source.Format == ImageFormat.Unknown); /*byte[] data = source.GetData(); * GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned); * IntPtr pointer = pinnedArray.AddrOfPinnedObject(); * * var img = new SciterImage(data, source.Width, source.Height); * _g.BlendImage(); * * pinnedArray.Free();*/ }
/// <summary> /// Draws the specified portion of the specified <see cref="OxyImage" /> at the specified location and with the specified size. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcWidth">Width of the portion of the source image to draw.</param> /// <param name="srcHeight">Height of the portion of the source image to draw.</param> /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param> /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param> /// <param name="destWidth">The width of the drawn image.</param> /// <param name="destHeight">The height of the drawn image.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate if set to <c>true</c>.</param> public virtual void DrawImage( OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) { }
/// <summary> /// Draws the image. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The SRC X.</param> /// <param name="srcY">The SRC Y.</param> /// <param name="srcWidth">Width of the SRC.</param> /// <param name="srcHeight">Height of the SRC.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="w">The w.</param> /// <param name="h">The h.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">interpolate if set to <c>true</c>.</param> public virtual void DrawImage( OxyImage source, uint srcX, uint srcY, uint srcWidth, uint srcHeight, double x, double y, double w, double h, double opacity, bool interpolate) { }
/// <summary> /// Draws the specified portion of the specified <see cref="OxyImage" /> at the specified location and with the specified size. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcWidth">Width of the portion of the source image to draw.</param> /// <param name="srcHeight">Height of the portion of the source image to draw.</param> /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param> /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param> /// <param name="destWidth">The width of the drawn image.</param> /// <param name="destHeight">The height of the drawn image.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate if set to <c>true</c>.</param> public override void DrawImage( OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) { this.w.WriteImage(srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, source); }
/// <summary> /// Writes the specified image. /// </summary> /// <param name="x">The x-coordinate.</param> /// <param name="y">The y-coordinate.</param> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="image">The image.</param> public void WriteImage(double x, double y, double width, double height, OxyImage image) { // http://www.w3.org/TR/SVG/shapes.html#ImageElement this.WriteStartElement("image"); this.WriteAttributeString("x", x); this.WriteAttributeString("y", y); this.WriteAttributeString("width", width); this.WriteAttributeString("height", height); this.WriteAttributeString("preserveAspectRatio", "none"); var imageData = image.GetData(); var encodedImage = new StringBuilder(); encodedImage.Append("data:"); encodedImage.Append("image/png"); encodedImage.Append(";base64,"); encodedImage.Append(Convert.ToBase64String(imageData)); this.WriteAttributeString("xlink", "href", null, encodedImage.ToString()); this.WriteEndElement(); }
/// <summary> /// Draws the specified image. /// </summary> /// <param name="rc">The render context.</param> /// <param name="image">The image.</param> /// <param name="x">The destination X position.</param> /// <param name="y">The destination Y position.</param> /// <param name="w">The width.</param> /// <param name="h">The height.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate the image if set to <c>true</c>.</param> public static void DrawImage( this IRenderContext rc, OxyImage image, double x, double y, double w, double h, double opacity, bool interpolate) { var info = rc.GetImageInfo(image); if (info == null) { return; } rc.DrawImage(image, 0, 0, info.Width, info.Height, x, y, w, h, opacity, interpolate); }
/// <summary> /// Writes a portion of the specified image. /// </summary> /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcWidth">Width of the portion of the source image to draw.</param> /// <param name="srcHeight">Height of the portion of the source image to draw.</param> /// <param name="destX">The destination x-coordinate.</param> /// <param name="destY">The destination y-coordinate.</param> /// <param name="destWidth">Width of the destination rectangle.</param> /// <param name="destHeight">Height of the destination rectangle.</param> /// <param name="image">The image.</param> public void WriteImage( double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, OxyImage image) { double x = destX - (srcX / srcWidth * destWidth); double width = image.Width / srcWidth * destWidth; double y = destY - (srcY / srcHeight * destHeight); double height = image.Height / srcHeight * destHeight; this.BeginClip(destX, destY, destWidth, destHeight); this.WriteImage(x, y, width, height, image); this.EndClip(); }
/// <summary> /// Draws the specified portion of the specified <see cref="OxyImage" /> at the specified location and with the specified size. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcWidth">Width of the portion of the source image to draw.</param> /// <param name="srcHeight">Height of the portion of the source image to draw.</param> /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param> /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param> /// <param name="destWidth">The width of the drawn image.</param> /// <param name="destHeight">The height of the drawn image.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate if set to <c>true</c>.</param> public override void DrawImage( OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) { PortableDocumentImage image; if (!this.images.TryGetValue(source, out image)) { image = PortableDocumentImageUtilities.Convert(source, interpolate); if (image == null) { // TODO: remove this when image decoding is working return; } this.images[source] = image; } this.doc.SaveState(); double x = destX - (srcX / srcWidth * destWidth); double width = image.Width / srcWidth * destWidth; double y = destY - (srcY / srcHeight * destHeight); double height = image.Height / srcHeight * destHeight; this.doc.SetClippingRectangle(destX, this.doc.PageHeight - (destY - destHeight), destWidth, destHeight); this.doc.Translate(x, this.doc.PageHeight - (y + height)); this.doc.Scale(width, height); this.doc.DrawImage(image); this.doc.RestoreState(); }
/// <summary> /// Gets the size of the specified image. /// </summary> /// <param name="source">The image source.</param> /// <returns> /// The image info. /// </returns> public virtual OxyImageInfo GetImageInfo(OxyImage source) { return(null); }
public static PlotModel ImageAnnotation() { var model = new PlotModel { Title = "ImageAnnotation", Subtitle = "Click the image" }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = -20, Maximum = 20 }); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = -10, Maximum = 10 }); OxyImage image; #if UNIVERSAL var assembly = typeof(PlotModel).GetTypeInfo().Assembly; #else var assembly = Assembly.GetExecutingAssembly(); #endif using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png")) { image = new OxyImage(stream); } var ia = new ImageAnnotation { ImageSource = image, X = new PlotLength(4, PlotLengthUnit.Data), Y = new PlotLength(2, PlotLengthUnit.Data), HorizontalAlignment = HorizontalAlignment.Right }; model.Annotations.Add(ia); // Handle left mouse clicks ia.MouseDown += (s, e) => { if (e.ChangedButton != OxyMouseButton.Left) { return; } ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right; model.InvalidatePlot(false); e.Handled = true; }; return model; }
public override OxyImageInfo GetImageInfo(OxyImage source) { var image = this.GetImage(source); return image == null ? null : new OxyImageInfo { Width = (uint)image.Width, Height = (uint)image.Height, DpiX = image.HorizontalResolution, DpiY = image.VerticalResolution }; }
public static PlotModel ImageAnnotation() { var model = new PlotModel { Title = "ImageAnnotation", PlotMargins = new OxyThickness(60, 4, 4, 60) }; model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); model.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); OxyImage image; #if UNIVERSAL var assembly = typeof(ImageAnnotationExamples).GetTypeInfo().Assembly; #else var assembly = Assembly.GetExecutingAssembly(); #endif using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png")) { image = new OxyImage(stream); } // Centered in plot area, filling width model.Annotations.Add(new ImageAnnotation { ImageSource = image, Opacity = 0.2, Interpolate = false, X = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea), Y = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea), Width = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Middle }); // Relative to plot area, inside top/right corner, 120pt wide model.Annotations.Add(new ImageAnnotation { ImageSource = image, X = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea), Y = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea), Width = new PlotLength(120, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top }); // Relative to plot area, above top/left corner, 20pt high model.Annotations.Add(new ImageAnnotation { ImageSource = image, X = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea), Y = new PlotLength(0, PlotLengthUnit.RelativeToPlotArea), OffsetY = new PlotLength(-5, PlotLengthUnit.ScreenUnits), Height = new PlotLength(20, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom }); // At the point (50,50), 200pt wide model.Annotations.Add(new ImageAnnotation { ImageSource = image, X = new PlotLength(50, PlotLengthUnit.Data), Y = new PlotLength(50, PlotLengthUnit.Data), Width = new PlotLength(200, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }); // At the point (50,20), 50 x units wide model.Annotations.Add(new ImageAnnotation { ImageSource = image, X = new PlotLength(50, PlotLengthUnit.Data), Y = new PlotLength(20, PlotLengthUnit.Data), Width = new PlotLength(50, PlotLengthUnit.Data), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top }); // Relative to the viewport, centered at the bottom, with offset (could also use bottom vertical alignment) model.Annotations.Add(new ImageAnnotation { ImageSource = image, X = new PlotLength(0.5, PlotLengthUnit.RelativeToViewport), Y = new PlotLength(1, PlotLengthUnit.RelativeToViewport), OffsetY = new PlotLength(-35, PlotLengthUnit.ScreenUnits), Height = new PlotLength(30, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top }); // Changing opacity for (int y = 0; y < 10; y++) { model.Annotations.Add( new ImageAnnotation { ImageSource = image, Opacity = (y + 1) / 10.0, X = new PlotLength(10, PlotLengthUnit.Data), Y = new PlotLength(y * 2, PlotLengthUnit.Data), Width = new PlotLength(100, PlotLengthUnit.ScreenUnits), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom }); } return model; }
/// <summary> /// The download completed, set the image. /// </summary> /// <param name="uri">The URI.</param> /// <param name="result">The result.</param> private void DownloadCompleted(string uri, Stream result) { if (result == null) { return; } var ms = new MemoryStream(); result.CopyTo(ms); var buffer = ms.ToArray(); var img = new OxyImage(buffer); this.images[uri] = img; lock (this.queue) { // Clear old items in the queue, new ones will be added when the plot is refreshed foreach (var queuedUri in this.queue) { // Remove the 'reserved' image this.images.Remove(queuedUri); } this.queue.Clear(); } this.PlotModel.InvalidatePlot(false); if (this.queue.Count > 0) { this.BeginDownload(); } }
public static PlotModel ImageAnnotation() { var model = new PlotModel("ImageAnnotation", "Click the image"); model.Axes.Add(new LinearAxis(AxisPosition.Bottom, -20, 20)); model.Axes.Add(new LinearAxis(AxisPosition.Left, -10, 10)); OxyImage image; var assembly = Assembly.GetExecutingAssembly(); using (var stream = assembly.GetManifestResourceStream("ExampleLibrary.Resources.OxyPlot.png")) { image = new OxyImage(stream); } var ia = new ImageAnnotation(image, new DataPoint(4, 2), HorizontalAlignment.Right); model.Annotations.Add(ia); // Handle left mouse clicks ia.MouseDown += (s, e) => { if (e.ChangedButton != OxyMouseButton.Left) { return; } ia.HorizontalAlignment = ia.HorizontalAlignment == HorizontalAlignment.Right ? HorizontalAlignment.Left : HorizontalAlignment.Right; model.InvalidatePlot(false); e.Handled = true; }; return model; }
/// <summary> /// Creates an image from 32-bit <c>true</c>-color pixels. /// </summary> /// <param name="pixels">The pixels indexed as [x,y]. [0,0] is top-left.</param> /// <param name="format">The image format.</param> /// <param name="encoderOptions">The encoder options.</param> /// <returns>An <see cref="OxyImage" /></returns> public static OxyImage Create(OxyColor[,] pixels, ImageFormat format, ImageEncoderOptions encoderOptions = null) { var encoder = GetEncoder(format, encoderOptions); var image = new OxyImage(encoder.Encode(pixels)); // TODO: remove when PNG decoder is implemented image.pixels = pixels; return image; }
/// <summary> /// Renders the series on the specified render context. /// </summary> /// <param name="rc">The rendering context.</param> /// <param name="model">The model.</param> public override void Render(IRenderContext rc, PlotModel model) { if (this.Matrix == null) { return; } int m = this.Matrix.GetLength(0); int n = this.Matrix.GetLength(1); var p0 = this.Transform(0, 0); var p1 = this.Transform(n, m); if (this.image == null) { var pixels = new OxyColor[m, n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { pixels[i, j] = Math.Abs(this.Matrix[m - 1 - i, j]) <= this.ZeroTolerance ? OxyColors.Transparent : this.NotZeroColor; } } this.image = OxyImage.PngFromArgb(pixels); } var clip = this.GetClippingRect(); var x0 = Math.Min(p0.X, p1.X); var y0 = Math.Min(p0.Y, p1.Y); var w = Math.Abs(p0.X - p1.X); var h = Math.Abs(p0.Y - p1.Y); rc.DrawClippedImage(clip, this.image, x0, y0, w, h, 1, false); var points = new List<ScreenPoint>(); if (this.GridInterval > 0) { var p2 = this.Transform(this.GridInterval, this.GridInterval); if (Math.Abs(p2.Y - p0.Y) > this.MinimumGridLineDistance) { for (int i = 1; i < n; i += this.GridInterval) { points.Add(this.Transform(0, i)); points.Add(this.Transform(n, i)); } } if (Math.Abs(p2.X - p0.X) > this.MinimumGridLineDistance) { for (int j = 1; j < m; j += this.GridInterval) { points.Add(this.Transform(j, 0)); points.Add(this.Transform(j, m)); } } } if (this.ShowDiagonal) { points.Add(this.Transform(0, 0)); points.Add(this.Transform(n, m)); } rc.DrawClippedLineSegments(points, clip, this.GridColor, 1, LineStyle.Solid, OxyPenLineJoin.Miter, true); if (this.BorderColor != null) { var borderPoints = new List<ScreenPoint> { this.Transform(0, 0), this.Transform(m, 0), this.Transform(0, n), this.Transform(m, n), this.Transform(0, 0), this.Transform(0, n), this.Transform(m, 0), this.Transform(m, n) }; rc.DrawClippedLineSegments( borderPoints, clip, this.BorderColor, 1, LineStyle.Solid, OxyPenLineJoin.Miter, true); } }
/// <summary> /// Writes the specified image. /// </summary> /// <param name="x">The x-coordinate.</param> /// <param name="y">The y-coordinate.</param> /// <param name="width">The width of the image.</param> /// <param name="height">The height of the image.</param> /// <param name="image">The image.</param> public void WriteImage(double x, double y, double width, double height, OxyImage image) { // http://www.w3.org/TR/SVG/shapes.html#ImageElement this.WriteStartElement("image"); this.WriteAttributeString("x", x); this.WriteAttributeString("y", y); this.WriteAttributeString("width", width); this.WriteAttributeString("height", height); this.WriteAttributeString("preserveAspectRatio", "none"); var imageData = image.GetData(); var encodedImage = new StringBuilder(); encodedImage.Append("data:"); encodedImage.Append("image/png"); encodedImage.Append(";base64,"); encodedImage.Append(Convert.ToBase64String(imageData)); this.WriteAttributeString("xlink", "href", null, encodedImage.ToString()); this.WriteClipPathAttribute(); this.WriteEndElement(); }
/// <summary> /// Draws the clipped image. /// </summary> /// <param name="rc">The render context.</param> /// <param name="clippingRect">The clipping rectangle.</param> /// <param name="source">The source.</param> /// <param name="x">The destination X position.</param> /// <param name="y">The destination Y position.</param> /// <param name="w">The width.</param> /// <param name="h">The height.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">interpolate if set to <c>true</c>.</param> public static void DrawClippedImage( this IRenderContext rc, OxyRect clippingRect, OxyImage source, double x, double y, double w, double h, double opacity, bool interpolate) { if (x > clippingRect.Right || x + w < clippingRect.Left || y > clippingRect.Bottom || y + h < clippingRect.Top) { return; } if (rc.SetClip(clippingRect)) { // The render context supports clipping, then we can draw the whole image rc.DrawImage(source, x, y, w, h, opacity, interpolate); rc.ResetClip(); return; } // The render context does not support clipping, we must calculate the rectangle var info = rc.GetImageInfo(source); if (info == null) { return; } // Fint the positions of the clipping rectangle normalized to image coordinates (0,1) var i0 = (clippingRect.Left - x) / w; var i1 = (clippingRect.Right - x) / w; var j0 = (clippingRect.Top - y) / h; var j1 = (clippingRect.Bottom - y) / h; // Find the origin of the clipped source rectangle var srcx = i0 < 0 ? 0u : i0 * info.Width; var srcy = j0 < 0 ? 0u : j0 * info.Height; srcx = (int)Math.Ceiling(srcx); srcy = (int)Math.Ceiling(srcy); // Find the size of the clipped source rectangle var srcw = i1 > 1 ? info.Width - srcx : (i1 * info.Width) - srcx; var srch = j1 > 1 ? info.Height - srcy : (j1 * info.Height) - srcy; srcw = (int)srcw; srch = (int)srch; if ((int)srcw <= 0 || (int)srch <= 0) { return; } // The clipped destination rectangle var destx = i0 < 0 ? x : x + (srcx / info.Width * w); var desty = j0 < 0 ? y : y + (srcy / info.Height * h); var destw = w * srcw / info.Width; var desth = h * srch / info.Height; rc.DrawImage(source, (uint)srcx, (uint)srcy, (uint)srcw, (uint)srch, destx, desty, destw, desth, opacity, interpolate); }
/// <summary> /// Draws the image. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The source executable.</param> /// <param name="srcY">The source asynchronous.</param> /// <param name="srcWidth">Width of the source.</param> /// <param name="srcHeight">Height of the source.</param> /// <param name="x">The executable.</param> /// <param name="y">The asynchronous.</param> /// <param name="w">The forward.</param> /// <param name="h">The authentication.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">if set to <c>true</c> [interpolate].</param> public override void DrawImage(OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double x, double y, double w, double h, double opacity, bool interpolate) { var image = this.GetImage(source); if (image != null) { ImageAttributes ia = null; if (opacity < 1) { var cm = new ColorMatrix { Matrix00 = 1f, Matrix11 = 1f, Matrix22 = 1f, Matrix33 = 1f, Matrix44 = (float)opacity }; ia = new ImageAttributes(); ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); } this.g.InterpolationMode = interpolate ? InterpolationMode.HighQualityBicubic : InterpolationMode.NearestNeighbor; int sx = (int)Math.Floor(x); int sy = (int)Math.Floor(y); int sw = (int)Math.Ceiling(x + w) - sx; int sh = (int)Math.Ceiling(y + h) - sy; var destRect = new Rectangle(sx, sy, sw, sh); this.g.DrawImage(image, destRect, (float)srcX - 0.5f, (float)srcY - 0.5f, (float)srcWidth, (float)srcHeight, GraphicsUnit.Pixel, ia); } }
/// <summary> /// Downloads the image from the specified URI. /// </summary> /// <param name="uri">The URI.</param> /// <returns>The image</returns> private OxyImage Download(string uri) { OxyImage img = null; var mre = new ManualResetEvent(false); var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.BeginGetResponse( r => { try { if (request.HaveResponse) { var response = request.EndGetResponse(r); var stream = response.GetResponseStream(); var ms = new MemoryStream(); stream.CopyTo(ms); var buffer = ms.ToArray(); img = new OxyImage(buffer); this.images[uri] = img; } } catch (Exception e) { var ie = e; while (ie != null) { System.Diagnostics.Debug.WriteLine(ie.Message); ie = ie.InnerException; } } finally { mre.Set(); } }, request); mre.WaitOne(); return img; }
/// <summary> /// Loads the image from the specified source. /// </summary> /// <param name="source">The image source.</param> /// <returns>A <see cref="Image" />.</returns> private Image GetImage(OxyImage source) { if (source == null) { return null; } if (!this.imagesInUse.Contains(source)) { this.imagesInUse.Add(source); } Image src; if (this.imageCache.TryGetValue(source, out src)) { return src; } Image btm; using (var ms = new MemoryStream(source.GetData())) { btm = Image.FromStream(ms); } this.imageCache.Add(source, btm); return btm; }
/// <summary> /// Gets the size of the specified image. /// </summary> /// <param name="source">The image source.</param> /// <returns> /// The image info. /// </returns> public virtual OxyImageInfo GetImageInfo(OxyImage source) { return null; }
/// <summary> /// Draws a portion of the specified <see cref="OxyImage" />. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The x-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcY">The y-coordinate of the upper-left corner of the portion of the source image to draw.</param> /// <param name="srcWidth">Width of the portion of the source image to draw.</param> /// <param name="srcHeight">Height of the portion of the source image to draw.</param> /// <param name="destX">The x-coordinate of the upper-left corner of drawn image.</param> /// <param name="destY">The y-coordinate of the upper-left corner of drawn image.</param> /// <param name="destWidth">The width of the drawn image.</param> /// <param name="destHeight">The height of the drawn image.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">interpolate if set to <c>true</c>.</param> public void DrawImage( OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) { }
/// <summary> /// Renders the series on the specified render context. /// </summary> /// <param name="rc">The rendering context.</param> /// <param name="model">The model.</param> public override void Render(IRenderContext rc, PlotModel model) { if (this.Matrix == null) { return; } int m = this.Matrix.GetLength(0); int n = this.Matrix.GetLength(1); var p0 = this.Transform(0, 0); var p1 = this.Transform(n, m); // note matrix index [i,j] maps to image index [j,i] if (this.image == null) { var pixels = new OxyColor[n, m]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { pixels[j, i] = Math.Abs(this.Matrix[i, j]) <= this.ZeroTolerance ? OxyColors.Transparent : this.NotZeroColor; } } this.image = OxyImage.Create(pixels, ImageFormat.Png); } var clip = this.GetClippingRect(); var x0 = Math.Min(p0.X, p1.X); var y0 = Math.Min(p0.Y, p1.Y); var w = Math.Abs(p0.X - p1.X); var h = Math.Abs(p0.Y - p1.Y); rc.DrawClippedImage(clip, this.image, x0, y0, w, h, 1, false); var points = new List<ScreenPoint>(); if (this.GridInterval > 0) { var p2 = this.Transform(this.GridInterval, this.GridInterval); if (Math.Abs(p2.Y - p0.Y) > this.MinimumGridLineDistance) { for (int i = 1; i < n; i += this.GridInterval) { points.Add(this.Transform(0, i)); points.Add(this.Transform(n, i)); } } if (Math.Abs(p2.X - p0.X) > this.MinimumGridLineDistance) { for (int j = 1; j < m; j += this.GridInterval) { points.Add(this.Transform(j, 0)); points.Add(this.Transform(j, m)); } } } if (this.ShowDiagonal) { points.Add(this.Transform(0, 0)); points.Add(this.Transform(n, m)); } rc.DrawClippedLineSegments(clip, points, this.GridColor, 1, null, LineJoin.Miter, true); if (this.BorderColor.IsVisible()) { var borderPoints = new[] { this.Transform(0, 0), this.Transform(m, 0), this.Transform(0, n), this.Transform(m, n), this.Transform(0, 0), this.Transform(0, n), this.Transform(m, 0), this.Transform(m, n) }; rc.DrawClippedLineSegments(clip, borderPoints, this.BorderColor, 1, null, LineJoin.Miter, true); } }