public LandscapeSky( LandscapeGenerator landscapeGenerator, ImageLoader imageLoader) { _landscapeGenerator = landscapeGenerator; _sky = imageLoader.Load("sky.png"); }
public LandscapeLand( LandscapeGenerator landscapeGenerator, ImageLoader imageLoader) { _landscapeGenerator = landscapeGenerator; _floor = imageLoader.Load("floor.png"); }
/// <summary> /// Gets the next valid image as a bitmap. /// </summary> /// <param name="skiaEncoder">The current skia encoder.</param> /// <param name="paths">The list of image paths.</param> /// <param name="currentIndex">The current checked indes.</param> /// <param name="newIndex">The new index.</param> /// <returns>A valid bitmap, or null if no bitmap exists after <c>currentIndex</c>.</returns> public static SKBitmap?GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList <string> paths, int currentIndex, out int newIndex) { var imagesTested = new Dictionary <int, int>(); SKBitmap?bitmap = null; while (imagesTested.Count < paths.Count) { if (currentIndex >= paths.Count) { currentIndex = 0; } bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _); imagesTested[currentIndex] = 0; currentIndex++; if (bitmap != null) { break; } } newIndex = currentIndex; return(bitmap); }
private async Task RenderResult(SKBitmap bitmap) { Timer.Start(); _instruction ??= new TwoSpheres(); _instruction.CreateScene(bitmap.Width, bitmap.Height, FloatColor.Black, true); await Task.Run(() => { foreach (var isRunning in _instruction.Render()) { if (isRunning) { Assign(bitmap, _instruction); _skiaContext !.SkCanvas.DrawBitmap(bitmap, new SKPoint(0, 0)); InvalidateVisual(); } else { break; } } }); Assign(bitmap, _instruction); _skiaContext !.SkCanvas.DrawBitmap(bitmap, new SKPoint(0, 0)); InvalidateVisual(); Timer.Stop(displayResult: DisplayTime); _bitmap = bitmap; }
public RibbonItem(string text, SKBitmap?image = null, EventHandler?onClick = null) { Text = text; Image = image; Click += onClick; }
private SKBitmap?GetNextValidImage(string[] paths, int currentIndex, out int newIndex) { var imagesTested = new Dictionary <int, int>(); SKBitmap?bitmap = null; while (imagesTested.Count < paths.Length) { if (currentIndex >= paths.Length) { currentIndex = 0; } bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out _); imagesTested[currentIndex] = 0; currentIndex++; if (bitmap != null) { break; } } newIndex = currentIndex; return(bitmap); }
public void SetBitmap(SKBitmap bitmap) { _bitmap?.Dispose(); _bitmap = bitmap; Reset(); }
protected override void SetUpPaints() { _bitPaint = MiscHelpers.GetBitmapPaint(); Assembly thisA = Assembly.GetAssembly(GetType()); _thisBit = ImageExtensions.GetSkBitmap(thisA, "SorryGameBoard.png"); _highlightPaint = MiscHelpers.GetStrokePaint(SKColors.Fuchsia, 3); }
protected override void SetUpPaints() { _thisA = Assembly.GetAssembly(GetType()); _bitPaint = MiscHelpers.GetBitmapPaint(); _thisBit = ImageExtensions.GetSkBitmap(_thisA, "gameboard.png"); _blackBorder = MiscHelpers.GetStrokePaint(SKColors.Black, 4); _aquaBorder = MiscHelpers.GetStrokePaint(SKColors.Aqua, 4); _limeBorder = MiscHelpers.GetStrokePaint(SKColors.LimeGreen, 4); }
public RibbonItem Add(string text, SKBitmap?image = null) { var item = new RibbonItem { Text = text, Image = image }; return(Add(item)); }
protected override void SetUpPaints() { Assembly thisA = Assembly.GetAssembly(GetType()); _fillPaint = MiscHelpers.GetSolidPaint(SKColors.LightGray); _borderPaint = MiscHelpers.GetStrokePaint(SKColors.White, 3); // try 3 _publicBit = ImageExtensions.GetSkBitmap(thisA, "publictrain.png"); _playerBit = ImageExtensions.GetSkBitmap(thisA, "playertrain.png"); // for testing, will be this one. _bitPaint = MiscHelpers.GetBitmapPaint(); _redPaint = MiscHelpers.GetSolidPaint(SKColors.Red); }
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 MenuItem Add(string text, SKBitmap?image = null) { var item = new MenuItem { Text = text, Image = image }; Add(item); return(item); }
public InternalWatermarkDrawer(IOptionsMonitor <DrawingExtensionOptions> options) : base(options) { _forePaint = Options.Watermark.Font.CreatePaint(Options.Colors.Fore); _alternPaint = Options.Watermark.Font.CreatePaint(Options.Colors.Alternate); // 限定水印图像文件的存储在模块的资源目录中 var watermarkFile = Options.Watermark.ImageFile .SetBasePath(Options.Directories.ResourceDirectory); if (watermarkFile.FileExists()) { _watermarkBitmap = SKBitmap.Decode(watermarkFile); } }
private void CreatePaints(int width) { Assembly thisA = Assembly.GetAssembly(GetType()); _bitPaint = MiscHelpers.GetBitmapPaint(); _arrowImage = ImageExtensions.GetSkBitmap(thisA, "arrows.png"); _highSpeed1 = ImageExtensions.GetSkBitmap(thisA, "highspeed1.png"); _highSpeed2 = ImageExtensions.GetSkBitmap(thisA, "highspeed2.png"); _boardBit = ImageExtensions.GetSkBitmap(thisA, "spinner.png"); _actualBoardSize = width; // try this way var diffs = _actualBoardSize / _intendedBoardSize; _actualArrowHeight = _intendedArrowHeight * diffs; _actualArrowWidth = _intendedArrowWidth * diffs; _didPaint = true; }
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); }
public void Init() { MainGraphics !.OriginalSize = new SKSize(55, 72); //change to what the original size is. _thisAssembly = Assembly.GetAssembly(this.GetType()); SKColor ThisColor = SKColors.Black; SKColor OtherColor = new SKColor(ThisColor.Red, ThisColor.Green, ThisColor.Blue, 70); //can experiment as needed. _selectPaint = MiscHelpers.GetSolidPaint(OtherColor); ThisColor = SKColors.White; OtherColor = new SKColor(ThisColor.Red, ThisColor.Green, ThisColor.Blue, 150); _pDrewPaint = MiscHelpers.GetSolidPaint(OtherColor); _cutImage = ImageExtensions.GetSkBitmap(_thisAssembly, "cut.png"); _flipImage = ImageExtensions.GetSkBitmap(_thisAssembly, "flip.png"); _redBrush = MiscHelpers.GetSolidPaint(SKColors.Red); _yellowBrush = MiscHelpers.GetSolidPaint(SKColors.Yellow); _blueBrush = MiscHelpers.GetSolidPaint(SKColors.Blue); _greenBrush = MiscHelpers.GetSolidPaint(SKColors.Green); _textBorder = MiscHelpers.GetStrokePaint(SKColors.Black, 2); _backPaint = MiscHelpers.GetSolidPaint(SKColors.Aqua); }
private void DrawGraphic(SKBitmap?graphic, float x, float y, float alpha, float scale, LandscapeItem item) { if (graphic == null) { return; } var newScale = scale * 0.5f; // we have loaded hi-res images var width = (graphic.Width * newScale); var height = (graphic.Height * newScale); var newX = _landscapeGenerator.NormaliseXPosition(x) - (width / 2.0f); var newY = y - (graphic.Height * newScale); _canvas.DrawBitmap(graphic, new SKRect( newX, newY, newX + width, newY + height)); }
void Invalidate() { int width, height; if (this.Log().IsEnabled(LogLevel.Trace)) { this.Log().Trace($"Render {renderCount++}"); } var dpi = 1; var resolution = _fbDev.ScreenSize; width = (int)resolution.Width; height = (int)resolution.Height; var scaledWidth = (int)(width * dpi); var scaledHeight = (int)(height * dpi); var info = new SKImageInfo(scaledWidth, scaledHeight, SKImageInfo.PlatformColorType, SKAlphaType.Premul); // reset the bitmap if the size has changed if (bitmap == null || info.Width != bitmap.Width || info.Height != bitmap.Height) { bitmap = new SKBitmap(scaledWidth, scaledHeight, _fbDev.PixelFormat, SKAlphaType.Premul); } using (var surface = SKSurface.Create(info, bitmap.GetPixels(out _))) { surface.Canvas.Clear(SKColors.White); surface.Canvas.Scale((float)dpi); WUX.Window.Current.Compositor.Render(surface, info); _fbDev.VSync(); Libc.memcpy(_fbDev.BufferAddress, bitmap.GetPixels(out _), new IntPtr(_fbDev.RowBytes * height)); } }
private void AddPictureBox(int left, int top, PictureBoxSizeMode mode, string?url = null, SKBitmap?image = null, bool enabled = true) { var pb = new PictureBox { Left = left, Top = top + 20, Height = 100, Width = 100, SizeMode = mode, Image = image, Enabled = enabled }; if (!string.IsNullOrWhiteSpace(url)) { pb.ImageLocation = url; } pb.Style.Border.Width = 1; Controls.Add(pb); }
/// <summary> /// Initializes a new instance of the MenuItem class. /// </summary> public MenuItem(string text, SKBitmap?image = null, EventHandler <MouseEventArgs>?onClick = null) { Text = text; Image = image; Click += onClick; }
private void GetImages() { _chocolateImage = ImageExtensions.GetSkBitmap(_thisAssembly !, "chocolate.png"); _strawberryImage = ImageExtensions.GetSkBitmap(_thisAssembly !, "strawberry.png"); }
public DrawResult(SKBitmap bitmap, SKCanvas canvas, ReadOnlyImageRef result) { _bitmap = bitmap; _canvas = canvas; _result = result; }
/// <summary> /// Adds a new MenuItem to the collection with the specified text, image, and Click handler. /// </summary> public MenuItem Add(string text, SKBitmap?image = null, EventHandler <MouseEventArgs>?onClick = null) { return(Add(new MenuItem(text, image, onClick))); }