/*public static SKBitmap Resize(this SKImage me, int width, int height) * { * var bmp = NewZeroedBitmap(width, height); * using var pixmap = bmp.PeekPixels(); * me.ScalePixels(pixmap, SKFilterQuality.Medium); * return bmp; * } * * public static SKBitmap Resize(this SKBitmap me, int width, int height) * { * var bmp = NewZeroedBitmap(width, height); * using var pixmap = bmp.PeekPixels(); * me.ScalePixels(pixmap, SKFilterQuality.Medium); * return bmp; * }*/ // resizes by resizing to same ratio and cropping out the rest public static SKBitmap SmartResize(this SKImage me, int width, int height) { var origRatio = (float)me.Width / me.Height; var newRatio = (float)width / height; var bmp = NewZeroedBitmap(width, height); using var c = new SKCanvas(bmp); switch (origRatio.CompareTo(newRatio)) { case -1: // new is wider // old is taller var newVal = me.Width / newRatio; c.DrawImage(me, SKRect.Create(0, (me.Height - newVal) / 2, me.Width, newVal), SKRect.Create(0, 0, width, height)); break; case 1: // old is wider // new is taller newVal = me.Height * newRatio; c.DrawImage(me, SKRect.Create((me.Width - newVal) / 2, 0, newVal, me.Height), SKRect.Create(0, 0, width, height)); break; case 0: // same c.DrawImage(me, SKRect.Create(0, 0, width, height)); break; } return(bmp); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e) { SKImageInfo info = e.Info; SKCanvas canvas = e.Surface.Canvas; canvas.Clear(); if (image != null) { if (kernelSelected) { using (SKPaint paint = new SKPaint()) { paint.FilterQuality = SKFilterQuality.High; paint.IsAntialias = false; paint.IsDither = false; paint.ImageFilter = SKImageFilter.CreateMatrixConvolution( sizeI, kernel, 1f, 0f, new SKPointI(1, 1), SKMatrixConvolutionTileMode.Clamp, false); canvas.DrawImage(image, info.Rect, ImageStretch.Uniform, paint: paint); image = e.Surface.Snapshot(); kernel = null; kernelSelected = false; } } else { canvas.DrawImage(image, info.Rect, ImageStretch.Uniform); } } }
/// <summary> /// Tries to add an element to the current element, from the right. /// </summary> /// <param name="Element">Element to add.</param> /// <returns>Result, if understood, null otherwise.</returns> public override ISemiGroupElement AddRight(ISemiGroupElement Element) { if (!(Element is Graph G)) { return(null); } GraphSettings Settings = new GraphSettings() { Width = this.width, Height = this.height }; SKImage Bmp = G.CreateBitmap(Settings); if (this.bitmap is null) { return(new GraphBitmap(Bmp)); } using (SKSurface Surface = SKSurface.Create(new SKImageInfo(Math.Max(Bmp.Width, this.width), Math.Max(Bmp.Height, this.height), SKImageInfo.PlatformColorType, SKAlphaType.Premul))) { SKCanvas Canvas = Surface.Canvas; Canvas.DrawImage(this.bitmap, 0, 0); Canvas.DrawImage(Bmp, 0, 0); Bmp.Dispose(); return(new GraphBitmap(Surface.Snapshot())); } }
public static void DrawImage(this SKCanvas canvas, SKImage image, SKRect dest, ImageStretch stretch, ImageAlignment horizontal = ImageAlignment.Center, ImageAlignment vertical = ImageAlignment.Center, SKPaint paint = null) { if (stretch == ImageStretch.Fill) { canvas.DrawImage(image, dest, paint); } else { float scale = 1; switch (stretch) { case ImageStretch.None: break; case ImageStretch.Uniform: scale = Math.Min(dest.Width / image.Width, dest.Height / image.Height); break; case ImageStretch.UniformToFill: scale = Math.Max(dest.Width / image.Width, dest.Height / image.Height); break; } SKRect display = CalculateDisplayRect(dest, scale * image.Width, scale * image.Height, horizontal, vertical); canvas.DrawImage(image, display, paint); } }
public void DrawImage(SKImage image, float x, float y, SKPaint paint = null) { canvas.DrawImage(image, x, y, paint); if (calculateBounds) { displayObject.addBoundingRect(x, y, image.Width, image.Height); } }
public void Close() { canvas.ClipPath(clip, SKClipOperation.Intersect, true); canvas.DrawImage(SKImage.FromBitmap(noise), new SKPoint(0, 0)); canvas.DrawImage(surface.Snapshot(), new SKPoint(0, 0), paint); canvas.Restore(); }
protected override void DrawImage(SKCanvas canvas, SKRect finalBoundingBox, SKPaint paint = null) { canvas.Clear(); canvas.DrawImage(_wings, finalBoundingBox, WingPaint); canvas.DrawImage(_body, finalBoundingBox, BodyPaint); canvas.DrawImage(_face, finalBoundingBox, paint); canvas.DrawImage(_clothes, finalBoundingBox, paint); canvas.DrawImage(_hair, finalBoundingBox, HairPaint); }
private static void CanvasDrawImage(SKCanvas canvas, SKImage image, SKRect dest, SKRect?src = null, SKPaint paint = null) { if (src == null) { canvas.DrawImage(image, dest, paint); } else { canvas.DrawImage(image, (SKRect)src, dest, paint); } }
public void Render(ref SKCanvas pSurface, SKRect pDestination) { //This is render changed variable, don't move it to set, that is wrong if (_RenderChanged.Update(ref mActive)) { if (mActive) { pSurface.DrawImage(mImage, pDestination, mDrawPaint); } else { pSurface.DrawImage(mImage, pDestination, mUndrawPaint); } } }
public void DrawImage(IImage image, Vector2 position, Vector2?scale = null, Color?tint = null) { var targetScale = scale ?? Vector2.One; var targetTint = tint ?? Color.White; var skImage = (SkiaImage)image; skPaint.Color = targetTint.ToSKColor(); skCanvas.DrawImage(skImage.SKImage, new SKRect(0, 0, skImage.Size.Width, skImage.Size.Height), new SKRect(position.X, position.Y, position.X + skImage.Size.Width * targetScale.X, position.Y + skImage.Size.Height * targetScale.Y), skPaint); }
public void Draw(SKCanvas canvas) { var info = this.info; // if there are no pixels, clean up and return if (info.Width == 0 || info.Height == 0) { return; } // if the memory size has changed, then reset the underlying memory if (bitmap != null && (bitmap.Handle == IntPtr.Zero || bitmap.Width != info.Width || bitmap?.Height != info.Height)) { FreeBitmap(); } if (bitmap == null) { bitmap = Bitmap.CreateBitmap(info.Width, info.Height, Bitmap.Config.Argb8888); bitmapCanvas = new Canvas(bitmap); } bitmap.EraseColor(Android.Graphics.Color.Transparent); base.Draw(bitmapCanvas); using (var image = SKImage.FromPixels(info, bitmap.LockPixels(), info.RowBytes)) { canvas.DrawImage(image, SKPoint.Empty); bitmap.UnlockPixels(); } }
public static void DrawImageUnscaledToRasterCanvas( SKCanvas outputCanvas, byte[] imageData) { using var sourceImage = SKImage.FromEncodedData(imageData); outputCanvas.DrawImage(sourceImage, SKRect.Create(0, 0, sourceImage.Width, sourceImage.Height)); }
public void Fill(SKCanvas canvas, SKPath path) { using (var paint = new SKPaint() { IsAntialias = true, Style = SKPaintStyle.Fill, }) { canvas.Save(); try { using (var img = SKImage.FromBitmap(Source)) { paint.Color = SKColors.White.WithAlpha((byte)(this.Opacity * 255)); canvas.ClipPath(path); canvas.DrawImage(img, path.Bounds, paint); } } catch (Exception e) { using (var errorPaint = new SKPaint { Color = SKColors.Red, Style = SKPaintStyle.Fill, }) { canvas.DrawRect(path.Bounds, errorPaint); errorPaint.Color = SKColors.White; canvas.DrawText(e.Message, path.Bounds.MidX, path.Bounds.MidY, errorPaint); } } canvas.Restore(); } }
public void Draw(SKCanvas graphics) { if (Hidden) { return; } var matrix = graphics.TotalMatrix; graphics.Translate(X, Y); int width = Width; int textY = (int)((ImageHeight + GroupNameSize.Height) / 2); if (Image != null) { var rect = new SKRect(0, 0, ImageWidth, ImageHeight); graphics.DrawImage(Image, rect); } graphics.DrawText(GroupName, ImageWidth + _padding, textY, _textPaint); DrawTriangle(graphics); graphics.SetMatrix(matrix); }
public bool is_valid => image_ != null; //?? I'm not sure if this is right //C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: void draw(SKCanvas& canvas, const SKPaint* paint = null) const public void draw(SKCanvas canvas, SKPaint paint = null) { var bounds = RasterCache.GetDeviceBounds(logical_rect_, canvas.TotalMatrix); canvas.ResetMatrix(); canvas.DrawImage(image_, bounds.Left, bounds.Top, paint); }
private static Pixel[] GetLinearPixels(SKImage image) { var height = image.Height; var width = image.Width; var linearPixels = ArrayPool <Pixel> .Shared.Rent(width *height); using (var bitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Bgra8888))) { using (var canvas = new SKCanvas(bitmap)) { canvas.DrawImage(image, 0, 0); } using (var pixmap = bitmap.PeekPixels()) { var pixels = pixmap.GetPixelSpan <SKColor>(); for (var i = 0; i < pixels.Length; i++) { var pixel = pixels[i]; linearPixels[i] = new Pixel( SrgbToLinear(pixel.Red), SrgbToLinear(pixel.Green), SrgbToLinear(pixel.Blue)); } } } return(linearPixels); }
private void CanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; _width = args.Info.Width; _height = args.Info.Height; ImageInfo = args.Info; canvas.Clear(); SKRect[] rects = new[] { new SKRect(0, 0, _width / 2f, _height / 2f), new SKRect(_width / 2f, 0, _width, (_height / 2f)), new SKRect(0, _height / 2f, _width / 2f, _height), new SKRect(_width / 2f, _height / 2f, _width, _height), }; using (var paint = new SKPaint() { StrokeWidth = 10, Color = SKColors.Black, Style = SKPaintStyle.Stroke }) { foreach (var rect in rects) { canvas.DrawRect(rect, paint); } } if (_files is null) { return; } int i = 0; foreach (MediaFile file in _files) { using (var paint = new SKPaint()) { paint.StrokeWidth = 15; paint.Color = SKColors.Black; paint.Style = SKPaintStyle.Fill; paint.TextAlign = SKTextAlign.Center; if (file == null) { return; } var bitmap = SKBitmap.Decode(file.GetStream()); canvas.DrawImage(SKImage.FromBitmap(bitmap), rects[i], paint); paint.TextSize = 250; canvas.DrawText(i.ToString(), new SKPoint(rects[i].MidX, rects[i].MidY), paint); i++; } } if (_isSaving) { SaveCanvas(surface); } }
private void SkCanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e) { var bitmap = SKBitmap.Decode(App.CroppedImage); // Init skcanvas SKImageInfo skImageInfo = e.Info; SKSurface skSurface = e.Surface; var im = SKImage.FromBitmap(bitmap); SKCanvas skCanvas = skSurface.Canvas; skCanvasWidth = skImageInfo.Width; skCanvasheight = skImageInfo.Height; var pictureFrame = SKRect.Create(0, 0, skCanvasWidth, skCanvasheight); SKSize imageSize = new SKSize(im.Width, im.Height); var dest = pictureFrame.AspectFit(imageSize); // draw the image var paint = new SKPaint { FilterQuality = SKFilterQuality.High // high quality scaling }; skCanvas.DrawImage(im, dest, paint); DrawAnalysis(skCanvas); }
public override void OnDraw(SKCanvas canvas, Attributes ignoreAttributes, Drawable?until) { if (until != null && this == until) { return; } if (Image != null) { using var skImagePaint = new SKPaint() { IsAntialias = true, FilterQuality = SKFilterQuality.High }; canvas.DrawImage(Image, SrcRect, DestRect, skImagePaint); } if (FragmentDrawable != null) { canvas.Save(); var skMatrixTotal = canvas.TotalMatrix; skMatrixTotal = skMatrixTotal.PreConcat(FragmentTransform); canvas.SetMatrix(skMatrixTotal); FragmentDrawable.Draw(canvas, ignoreAttributes, until); canvas.Restore(); } }
public void Draw(SKCanvas canvas, CameraComponent camera) { foreach (var spriteData in _currentFrame.Sprites) { canvas.DrawImage(Image, Paint, spriteData); } }
static SKColor[] GetPixels(SKImage image) { using var bmp = new SKBitmap(image.Width, image.Height); using var cnv = new SKCanvas(bmp); cnv.DrawImage(image, 0, 0); return(bmp.Pixels); }
void DrawTrajectory(SKCanvas canvas) { SKPaint paint = new SKPaint { Color = SKColor.Parse("#3949AB"), Style = SKPaintStyle.StrokeAndFill, StrokeWidth = 4, MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 1) }; for (int i = 1; i < ViewModel.GameTrajectory.Count(); i++) { SKPoint prvGridPoint = ViewModel.GameTrajectory[i - 1]; SKPoint start = ViewModel.GetGridPoint(prvGridPoint); SKPoint curGridPoint = ViewModel.GameTrajectory[i]; SKPoint end = ViewModel.GetGridPoint(curGridPoint); canvas.DrawLine(start, end, paint); } paint.Color = SKColors.Red; paint.Shader = null; paint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 2); DrawChoice(canvas); float starSize = ViewModel.CellSize * 0.75f; var bitmap = SKBitmap.Decode(Helper.getResourceStream("Images.star.png")); SKImage image = SKImage.FromBitmap(bitmap); SKPoint last = ViewModel.GameTrajectory.Last(); SKRect rect = new SKRect { Location = ViewModel.GetGridPoint(last) - new SKPoint(starSize, starSize), Size = new SKSize(starSize * 2, starSize * 2) }; canvas.DrawImage(image, rect); }
private static void DrawContent(CalloutStyle callout, SKCanvas canvas) { // Draw content if (callout.Content >= 0) { var strokeWidth = callout.StrokeWidth < 1 ? 1 : callout.StrokeWidth; var offsetX = callout.ShadowWidth + strokeWidth * 2 + (callout.Padding.Left < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5f : (float)callout.Padding.Left); var offsetY = callout.ShadowWidth + strokeWidth * 2 + (callout.Padding.Top < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5f : (float)callout.Padding.Top); switch (callout.ArrowAlignment) { case ArrowAlignment.Left: offsetX += callout.ArrowHeight; break; case ArrowAlignment.Top: offsetY += callout.ArrowHeight; break; } var offset = new SKPoint(offsetX, offsetY); if (callout.Type == CalloutType.Custom) { // Get size of content var bitmapInfo = BitmapHelper.LoadBitmap(BitmapRegistry.Instance.Get(callout.Content)); switch (bitmapInfo?.Type) { case BitmapType.Bitmap: canvas.DrawImage(bitmapInfo.Bitmap, offset); break; case BitmapType.Sprite: throw new Exception(); case BitmapType.Svg: if (bitmapInfo.Svg != null) { using var skPaint = new SKPaint() { IsAntialias = true }; canvas.DrawPicture(bitmapInfo.Svg.Picture, offset, skPaint); } break; } } else if (callout.Type == CalloutType.Single || callout.Type == CalloutType.Detail) { var picture = (SKPicture)BitmapRegistry.Instance.Get(callout.Content); using var skPaint = new SKPaint() { IsAntialias = true }; canvas.DrawPicture(picture, offset, skPaint); } } }
public override void Draw(SKCanvas c) { if (!Visible) { return; } if (screenshot != null) { // Save view matrix, scale the screenshot to make it zoomed in and then restore c.Save(); c.Scale(zoomFactor); c.DrawImage(screenshot, Bounds.Left - 1, Bounds.Top - 1); c.Restore(); // Crosshair if (CrosshairVisible) { var xs = CrosshairSize / 2; c.DrawLine(Bounds.MidX - xs, Bounds.MidY, Bounds.MidX + xs, Bounds.MidY, PaintCrosshair); c.DrawLine(Bounds.MidX, Bounds.MidY - xs, Bounds.MidX, Bounds.MidY + xs, PaintCrosshair); } } base.Draw(c); }
public void DrawTransparentImageWithHighFilterQualityWithUnpremul() { var oceanColor = (SKColor)0xFF9EB4D6; var landColor = (SKColor)0xFFACB69B; using (var bitmap = new SKBitmap(new SKImageInfo(300, 300))) using (var canvas = new SKCanvas(bitmap)) { canvas.Clear(oceanColor); // decode the bitmap var path = Path.Combine(PathToImages, "map.png"); using (var mapBitmap = SKBitmap.Decode(path)) using (var mapImage = SKImage.FromBitmap(mapBitmap)) { var bounds = SKRect.Create(-259.9664f, -260.4489f, 1221.1876f, 1020.23273f); // draw the bitmap using (var paint = new SKPaint { FilterQuality = SKFilterQuality.High }) { canvas.DrawImage(mapImage, bounds, paint); } } // check values Assert.Equal(oceanColor, bitmap.GetPixel(30, 30)); Assert.Equal(landColor, bitmap.GetPixel(270, 270)); } }
public ProcessImage Encode(SKImage img, ProcessImageType toType, bool flipHorizontal, bool flipVertical) { if (flipHorizontal || flipVertical) { using SKBitmap bmp = new SKBitmap(img.Width, img.Height); using SKCanvas surface = new SKCanvas(bmp); surface.Scale(flipHorizontal ? -1 : 1, flipVertical ? -1 : 1, flipHorizontal ? img.Width / 2f : 0, flipVertical ? img.Height / 2f : 0); surface.DrawImage(img, 0, 0); img = SKImage.FromBitmap(bmp); } if (toType == ProcessImageType.JPEG) { return(new ProcessImage { Load = img.Encode(SKEncodedImageFormat.Jpeg, 95).ToArray(), Type = toType, Width = img.Width, Height = img.Height }); } if (toType == ProcessImageType.PNG) { return(new ProcessImage { Load = img.Encode(SKEncodedImageFormat.Png, 95).ToArray(), Type = toType, Width = img.Width, Height = img.Height }); } if (toType == ProcessImageType.RGBA8) { SKBitmap bmp = SKBitmap.FromImage(img); return(new ProcessImage { Load = bmp.Bytes, Height = bmp.Height, Type = toType, Width = bmp.Width }); } throw new FormatException("Format conversion not implemented"); }
//SKPaint resize = new SKPaint() { IsAntialias = false, FilterQuality = SKFilterQuality.High }; public void Draw(SKCanvas canvas, int x, int y, int scrollX = 0, SKPaint paint = null) { scaleX = x * All.GAME_SCALE; scaleY = y * All.GAME_SCALE; tempSKRect = new SKRect(All.DECAL_MAP_X + scaleX + scrollX, All.DECAL_MAP_Y + scaleY, All.DECAL_MAP_X + scaleX + WidthScale + scrollX, All.DECAL_MAP_Y + scaleY + HeightScale); //canvas.DrawBitmap(All.TilesScale, sourcesScale[StepAnim], tempSKRect, paint); canvas.DrawImage(All.TilesScaleImage, sourcesScale[StepAnim], tempSKRect, paint); }
public override void DrawImage(Image image, RectangleF target, RectangleF source, float opacity) { var skiaImage = (SkiaImage)image; PreparePaint(skPaint); skPaint.Color = new SKColor(255, 255, 255, (byte)(opacity * 255)); skCanvas.DrawImage(skiaImage.SKImage, source.ToSkia(), target.ToSkia(), skPaint); }
protected virtual void DrawImage(SKCanvas canvas, SKRect finalBoundingBox, SKPaint paint = null) { if (_image == null) { return; } canvas.DrawImage(_image, finalBoundingBox, paint); }
public void DrawNoDecal(SKCanvas canvas, int x, int y) { scaleX = x * All.GAME_SCALE; scaleY = y * All.GAME_SCALE; tempSKRect = new SKRect(scaleX, scaleY, scaleX + WidthScale, scaleY + HeightScale); //canvas.DrawBitmap(All.TilesScale, sourcesScale[StepAnim], tempSKRect); canvas.DrawImage(All.TilesScaleImage, sourcesScale[StepAnim], tempSKRect); }