private void HandlePan(object sender, PanUpdatedEventArgs puea) { Debug.WriteLine($"{puea.StatusType} ({puea.TotalX},{puea.TotalY})"); switch (puea.StatusType) { case GestureStatus.Started: _startPanM = _m; break; case GestureStatus.Running: float canvasTotalX = (float)puea.TotalX * _screenScale; float canvasTotalY = (float)puea.TotalY * _screenScale; SKMatrix canvasTranslation = SKMatrix.MakeTranslation(canvasTotalX, canvasTotalY); SKMatrix.Concat(ref _m, ref canvasTranslation, ref _startPanM); _currentTransformM = canvasTranslation; _canvasV.InvalidateSurface(); break; default: _startPanM = SKMatrix.MakeIdentity(); // force textLayer to regenerate _textLayer?.Dispose(); _textLayer = null; _canvasV.InvalidateSurface(); break; } }
public void SetBitmap(SKBitmap bitmap) { _bitmap?.Dispose(); _bitmap = bitmap; Reset(); }
void UpdateScreen(string ms, int r, int c, bool encrypted, int height, int width) { if (ms != null) { if (height != pasth || width != pastw) { pasth = height; pastw = width; clearsurface(); } if (encrypted) { ms = Decoded(ms.Substring(0, 200)) + ms.Substring(200); } stream = new MemoryStream(Convert.FromBase64String(ms)); NewPart = SKBitmap.Decode(stream); stream.Close(); stream?.Dispose(); d1 = 1.0 * width / height; if (d > d1) { ih = heit / 10; iw = ih * d1; } else { iw = wdth / 10; ih = iw / d1; } NewPart = NewPart.Resize(new SKSizeI((int)iw, (int)ih), SKFilterQuality.High); NewPartPosX = c * (int)iw; NewPartPosY = r * (int)ih; surface.Canvas.DrawBitmap(NewPart, NewPartPosX, NewPartPosY); NewPart?.Dispose(); } }
private SKImage Combine(Stream fighterFile, Stream rankFile) { SKBitmap fighter = null; SKBitmap rank = null; try { fighterFile?.Seek(0, SeekOrigin.Begin); rankFile?.Seek(0, SeekOrigin.Begin); fighter = SKBitmap.Decode(fighterFile); rank = SKBitmap.Decode(rankFile); using (var tempSurface = SKSurface.Create(new SKImageInfo(fighter.Width, fighter.Height))) { var canvas = tempSurface.Canvas; canvas.Clear(SKColors.Transparent); canvas.DrawBitmap(fighter, SKRect.Create(0, 0, fighter.Width, fighter.Height)); canvas.DrawBitmap(rank, SKRect.Create(fighter.Width - rank.Width - 10, 0, rank.Width, rank.Height)); return(tempSurface.Snapshot()); } } finally { fighter?.Dispose(); rank?.Dispose(); } }
private void GetImage() { _imageBitmap?.Dispose(); XamTweet.CachedImage cached = new CachedImage(); switch (Resource) { case Resource.Like: cached = Get(XamTweet.Forms.Resources.Images.Image.Like); break; case Resource.LikeEmpty: cached = Get(XamTweet.Forms.Resources.Images.Image.LikeEmpty); break; case Resource.Reply: cached = Get(XamTweet.Forms.Resources.Images.Image.Reply); break; case Resource.Retweet: cached = Get(XamTweet.Forms.Resources.Images.Image.Retweet); break; case Resource.Share: cached = Get(XamTweet.Forms.Resources.Images.Image.Share); break; } _imageBitmap = SKBitmap.Decode(cached.Bytes); }
public Stream GetBitmap(double nHour, double nMinute, double nSecond, int width = 512, int height = 512, bool bDrawBackImage = false) { if (bitmap == null || bitmap.Width != width || bitmap.Height != height) { bitmap?.Dispose(); bitmap = new SKBitmap(width, height); } SKCanvas canvas = new SKCanvas(bitmap); DrawCanvas(canvas, nHour, nMinute, nSecond, width, height, bDrawBackImage); // create an image COPY //SKImage image = SKImage.FromBitmap(bitmap); // OR // create an image WRAPPER SKImage image = SKImage.FromPixels(bitmap.PeekPixels()); // encode the image (defaults to PNG) SKData encoded = image.Encode(); // get a stream over the encoded data Stream stream = encoded.AsStream(); return(stream); }
private void GetContactImage() { _imageBitmap?.Dispose(); var defaultImage = XamTweet.Forms.Resources.Images.Image.DefaultUser; var cached = _imageCacheService.Cache.FirstOrDefault(x => x.Id.Equals(defaultImage)); if (cached is null) { using (var stream = GetType().GetTypeInfo().Assembly .GetManifestResourceStream(XamTweet.Forms.Resources.Images.Image.DefaultUser)) { var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); cached = new XamTweet.CachedImage { Id = defaultImage, Bytes = bytes }; _imageCacheService.Add(cached); } } _imageBitmap = SKBitmap.Decode(cached.Bytes); }
public byte[] ResizePhoto(Stream photoStream) { var bitmap = SKBitmap.Decode(photoStream); SKImage image; SKBitmap newBitmap = null; int maxMpix = 12 * 1000 * 1000; RtbLog.AppendText($"Image size: {bitmap.Width}x{bitmap.Height}\n"); if ((bitmap.Width * bitmap.Height) >= maxMpix - 1) // more than 12 MP { newBitmap = bitmap.Resize(ResizeUntilMPixels(bitmap.Info, maxMpix), SKFilterQuality.High); image = SKImage.FromBitmap(newBitmap); RtbLog.AppendText($"Image resized: {newBitmap.Width}x{newBitmap.Height}\n"); } else { image = SKImage.FromBitmap(bitmap); } using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 90)) { var array = data.ToArray(); bitmap.Dispose(); newBitmap?.Dispose(); image.Dispose(); return(array); } }
/// <inheritdoc /> public void Dispose() { lock (_disposeLock) { Bitmap?.Dispose(); IsDisposed = true; } }
public void SetBounds(int AWidth, int AHeight) { // Prevent divisions by zero downstream if (AWidth == 0) { AWidth = 1; } if (AHeight == 0) { AHeight = 1; } int PrevDisplayWidth = 1; int PrevDisplayHeight = 1; if (BitmapCanvas != null) { PrevDisplayWidth = BitmapCanvas.Width; PrevDisplayHeight = BitmapCanvas.Height; } BitmapCanvas?.Dispose(); BitmapCanvas = new SKBitmap(AWidth, AHeight, SKColorType.Rgba8888, SKAlphaType.Unpremul); DrawCanvas?.Dispose(); DrawCanvas = new SKCanvas(BitmapCanvas); if (BitmapCanvas != null) { if (PrevDisplayWidth > 0 && PrevDisplayHeight > 0) { if (SquareAspect) { if (HoldOriginOnResize) { SetWorldBounds(OriginX, OriginY, OriginX + WidthX * ((double)AWidth / (double)PrevDisplayWidth), OriginY + WidthY * ((double)AHeight / (double)PrevDisplayHeight), 0); } else { SetWorldBounds(LimitX - WidthX * ((double)AWidth / (double)PrevDisplayWidth), LimitY - WidthY * ((double)AHeight / (double)PrevDisplayHeight), LimitX, LimitY, 0); } } else { SetWorldBounds(OriginX, OriginY, OriginX + WidthX, OriginY + WidthY, 0); } } } CalculateXYOffsets(); }
private bool _disposed; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposed && disposing) { _disposed = true; SKBitmap?.Dispose(); SKBitmap = null; } }
public void Dispose() { if (IsDisposed) { return; } _bitmap?.Dispose(); IsDisposed = true; }
private bool _disposed; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposed && disposing) { _disposed = true; SKBitmap?.Dispose(); SKBitmap = null; P42.Utils.Debug.RemoveFromCensus(this); } }
private void SetMainBitmap(SKBitmap bitmap) { outImageWidht = config?.IsOutImageAutoSize ?? false ? bitmap?.Width ?? 1 : config?.OutImageWidht ?? 1; outImageHeight = config?.IsOutImageAutoSize ?? false ? bitmap?.Height ?? 1 : config?.OutImageHeight ?? 1; backgroundBitmap?.Dispose(); backgroundBitmap = config.BackgroundType == BackgroundType.StretchedImage ? SKBitmapBuilder.GetBlurBitmap(bitmap, new SKRect(0, 0, outImageWidht, outImageHeight)) : null; mainBitmap?.Bitmap?.Dispose(); if (mainBitmap == null) { mainBitmap = new TouchManipulationBitmap(bitmap, BitmapType.Main, null); } else { mainBitmap.Bitmap = bitmap; } SetMainBitmapMatrix(); }
protected override bool OnDrawn(Context cr) { Stopwatch?sw = null; if (this.Log().IsEnabled(LogLevel.Trace)) { sw = Stopwatch.StartNew(); this.Log().Trace($"Render {renderCount++}"); } var scaledWidth = (int)(AllocatedWidth * _dpi); var scaledHeight = (int)(AllocatedHeight * _dpi); // reset the surfaces (skia/cairo) and bitmap if the size has changed if (_surface == null || scaledWidth != _bwidth || scaledHeight != _bheight) { _gtkSurface?.Dispose(); _surface?.Dispose(); _bitmap?.Dispose(); var info = new SKImageInfo(scaledWidth, scaledHeight, _colorType, SKAlphaType.Premul); _bitmap = new SKBitmap(info); _bwidth = _bitmap.Width; _bheight = _bitmap.Height; var pixels = _bitmap.GetPixels(out _); _surface = SKSurface.Create(info, pixels); _gtkSurface = new ImageSurface(pixels, Format.Argb32, _bwidth, _bheight, _bwidth * 4); } var canvas = _surface.Canvas; using (new SKAutoCanvasRestore(canvas, true)) { canvas.Clear(BackgroundColor); canvas.Scale(_dpi); WUX.Window.Current.Compositor.Render(_surface); } _gtkSurface !.MarkDirty(); cr.Save(); cr.Scale(1 / _dpi, 1 / _dpi); cr.SetSourceSurface(_gtkSurface, 0, 0); cr.Paint(); cr.Restore(); if (this.Log().IsEnabled(LogLevel.Trace)) { sw?.Stop(); this.Log().Trace($"Frame: {sw?.Elapsed}"); } return(true); }
public void Dispose() { _bitmap?.Dispose(); _codec?.Dispose(); _image?.Dispose(); if (_disposeStream) { _stream?.Dispose(); } }
protected override void Dispose(bool disposing) { _disposed = true; foreach (ProfileElement profileElement in Children) { profileElement.Dispose(); } _folderBitmap?.Dispose(); base.Dispose(disposing); }
private bool disposedValue; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { SKBitmap?.Dispose(); SKBitmap = null; } disposedValue = true; } }
public void Dispose() { Font?.Dispose(); Font = null; FontStream?.Dispose(); FontStream = null; FontSource?.Dispose(); FontSource = null; ImageBitmap?.Dispose(); ImageBitmap = null; ImageData?.Dispose(); ImageData = null; }
private static void UpdateImageSource(BindableObject bindable) { if (bindable is MenuItem item) { var resourceName = GetResourceName(bindable); if (string.IsNullOrWhiteSpace(resourceName)) { return; } var baseUrl = DependencyService.Get <IBaseUrl>(); var stream = baseUrl.GetDrawableImageStream(resourceName); if (stream != null) { using (stream) { var bitmap = SKBitmap.Decode(stream); SKBitmap newBitmap = null; try { newBitmap = new SKBitmap( Convert.ToInt32(bitmap.Width * BitmapScale), Convert.ToInt32(bitmap.Height * BitmapScale)); using (var canvas = new SKCanvas(newBitmap)) { var backgroundColor = GetBackgroundColor(bindable); canvas.Clear(backgroundColor.ToSKColor()); canvas.DrawBitmap(bitmap, new SKRect(0, 0, newBitmap.Width, newBitmap.Height)); } var newImageSource = (SKBitmapImageSource)newBitmap; item.IconImageSource = newImageSource; newBitmap = null; } finally { newBitmap?.Dispose(); } } } } }
private void RenderBitmap(SKCanvas canvas) { if (Image == null) { return; } if (_lastClipWidth != canvas.ClipDeviceBounds.Width || _scaledBitmap == null) { _scaledBitmap?.Dispose(); _scaledBitmap = ResizeBitmap(canvas.ClipDeviceBounds, Image.Data); _lastClipWidth = canvas.ClipDeviceBounds.Width; } canvas.DrawBitmap(_scaledBitmap, 0, 0); }
private async void LoadSkBitmap() { var path = ContentImg; var newBitmap = await Task.Run(() => { using (var stream = new SKFileStream(path)) { return(SKBitmap.Decode(stream)); } }); _contentBitmap?.Dispose(); _contentBitmap = newBitmap; InvalidateSurface(); }
private static SKBitmap ZoomAndRotate(SKBitmap originalBitmap, double zoom, bool isRotated, float rotation, bool isKeystoned, float keystone) { var rotatedAndZoomed = new SKBitmap(originalBitmap.Width, originalBitmap.Height); using (var tempCanvas = new SKCanvas(rotatedAndZoomed)) { var zoomedX = originalBitmap.Width * zoom / -2f; var zoomedY = originalBitmap.Height * zoom / -2f; var zoomedWidth = originalBitmap.Width * (1 + zoom); var zoomedHeight = originalBitmap.Height * (1 + zoom); if (isRotated) { tempCanvas.RotateDegrees(rotation, originalBitmap.Width / 2f, originalBitmap.Height / 2f); } tempCanvas.DrawBitmap( originalBitmap, SKRect.Create( (float)zoomedX, (float)zoomedY, (float)zoomedWidth, (float)zoomedHeight )); // blows up the bitmap, which is cut off later if (isRotated) { tempCanvas.RotateDegrees(rotation, -1 * originalBitmap.Width / 2f, originalBitmap.Height / 2f); } } SKBitmap keystoned = null; if (isKeystoned) { keystoned = new SKBitmap(originalBitmap.Width, originalBitmap.Height); using (var tempCanvas = new SKCanvas(keystoned)) { tempCanvas.SetMatrix(TaperTransform.Make(new SKSize(originalBitmap.Width, originalBitmap.Height), keystone > 0 ? TaperSide.Left : TaperSide.Right, TaperCorner.Both, 1 - Math.Abs(keystone))); tempCanvas.DrawBitmap(rotatedAndZoomed, 0, 0); rotatedAndZoomed.Dispose(); } } return(keystoned ?? rotatedAndZoomed); }
public static SKBitmap CropImage(SKBitmap original, PointF cropTopLeft, PointF cropBottomRight) { var cropRect = new SKRectI { Left = (int)cropTopLeft.X, Top = (int)cropTopLeft.Y, Right = (int)cropBottomRight.X, Bottom = (int)cropBottomRight.Y }; SKBitmap bitmap = new SKBitmap(cropRect.Width, cropRect.Height); original.ExtractSubset(bitmap, cropRect); original.Dispose(); return(bitmap); }
public void Dispose() { if (IconImage != null) { IconImage.Dispose(); } if (RarityBackgroundImage != null) { RarityBackgroundImage.Dispose(); } DisplayName = ""; ShortDescription = ""; Banner = ""; Price = 0; Width = 0; Height = 0; }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { aspectRatio = null; touchPoints?.Clear(); touchPoints = null; touchPointsInside?.Clear(); touchPointsInside = null; } bitmap?.Dispose(); bitmap = null; disposedValue = true; } }
public void Dispose() { if (IconImage != null) { IconImage.Dispose(); } if (RarityBackgroundImage != null) { RarityBackgroundImage.Dispose(); } RarityColors = null; DisplayName = ""; Description = ""; ShortDescription = ""; Height = 0; Width = 0; }
public SKBitmap CreateBitmap(TileTextureCollection c, int scale = 1, SKBitmap?bmp = null) { scale = Math.Max(scale, 1); var expectedSize = ComputeRenderedSize(c); expectedSize = new IntDimension(expectedSize.Width * scale, expectedSize.Height * scale); if (bmp == null || bmp.Width != expectedSize.Width || bmp.Height != expectedSize.Height) { bmp?.Dispose(); bmp = new SKBitmap(expectedSize.Width, expectedSize.Height); } using var ctx = new SKCanvas(bmp); ctx.Scale(scale, scale); ctx.Clear(SKColor.Empty); Produce(ctx, c); return(bmp); }
private void skiaView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) { _skBitmap?.Dispose(); //载入底图 var filePath = Value < 0 ? $"{_imageFolder}/test.jpg" : $"{_imageFolder}/{Value % 5}.jpg"; _skBitmap = SKBitmap.Decode(filePath); // the the canvas and properties var canvas = e.Surface.Canvas; //绘图 DrawSkia(canvas, e.Info, _skBitmap, labelDisplay.Text); if (Value >= 0) { labelRecvNumber.Text = (++_recvNumber).ToString(); } }
public SKBitmap GetThumbnail(SKBitmap originalImage, Size thumbnailArea) { if (originalImage == null) throw new ArgumentNullException(nameof(originalImage)); var originalSize = new Size(originalImage.Width, originalImage.Height); var thumbnailSize = GetThumbnailSize(originalSize, thumbnailArea); var thumbnail = new SKBitmap(thumbnailSize.Width, thumbnailSize.Height); try { originalImage.Resize(thumbnail, SKBitmapResizeMethod.Mitchell); } catch (Exception) { thumbnail.Dispose(); throw; } return thumbnail; }