private async void ExecuteLoaded(object obj) { SetHeaderAttributes(true, "Составляем коллаж"); merge = BitmapFactory.New(300, ((headModel.GetImagesForCollage().Count / 2) + (headModel.GetImagesForCollage().Count % 2)) * 150); var t = await createCollate(); if (t == true) { for (int i = 0; i < _listBmp.Count; i++) { if (i % 2 == 1) { merge.Blit(new Rect(150, 150 * (i / 2), 150, 150), new WriteableBitmap(_listBmp[i]), new Rect(0, 0, _listBmp[i].PixelWidth, _listBmp[i].PixelHeight)); //draw the photo first } else if (i % 2 == 0) { merge.Blit(new Rect(0, 150 * (i / 2), 150, 150), new WriteableBitmap(_listBmp[i]), new Rect(0, 0, _listBmp[i].PixelWidth, _listBmp[i].PixelHeight)); //draw the photo first } } using (MemoryStream ms = new MemoryStream()) { merge.SaveJpeg(ms, merge.PixelWidth, merge.PixelHeight, 0, 100); BitmapImage bmp = new BitmapImage(); bmp.SetSource(ms); Collage = bmp; SetHeaderAttributes(false, "Коллаж готов"); } } }
private void ChangeBitmap(Point touch_point) { if (this.selectedMode == MODE_ORIGINAL || this.selectedMode == MODE_EFFECTED) { int width = Math.Min(this.brushBitmap.PixelWidth, this.editedBitmap.PixelWidth); int height = Math.Min(this.brushBitmap.PixelHeight, this.editedBitmap.PixelHeight); Rect img_rect = new Rect(); img_rect.X = Math.Min(Math.Max(0, touch_point.X - width / 2), this.editedBitmap.PixelWidth - width); img_rect.Y = Math.Min(Math.Max(0, touch_point.Y - height / 2), this.editedBitmap.PixelHeight - height); img_rect.Width = width; img_rect.Height = height; Rect brh_rect = new Rect(0, 0, width, height); WriteableBitmap brush_bitmap = new WriteableBitmap(width, height); if (this.selectedMode == MODE_ORIGINAL) { brush_bitmap.Blit(brh_rect, this.originalBitmap, img_rect, WriteableBitmapExtensions.BlendMode.None); } else { brush_bitmap.Blit(brh_rect, this.effectedBitmap, img_rect, WriteableBitmapExtensions.BlendMode.None); } brush_bitmap.Blit(brh_rect, this.brushBitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Mask); this.editedBitmap.Blit(img_rect, brush_bitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Alpha); this.EditorImage.Source = this.editedBitmap; } }
protected override void OnRender(DrawingContext dc) { var bitmap = new WriteableBitmap((int)(Screen.PixelWidth * this.Zoom), (int)(Screen.PixelHeight * this.Zoom), 96, 96, PixelFormats.Pbgra32, null); base.OnRender(dc); var size = Screen.Tileset.TileSize * this.Zoom; for (int y = 0; y < Screen.Height; y++) { for (int x = 0; x < Screen.Width; x++) { var tile = Screen.TileAt(x, y); var location = tile.Sprite.CurrentFrame.SheetLocation; var rect = new Rect(0, 0, location.Width, location.Height); if (_grayscale) { var image = SpriteBitmapCache.GetOrLoadFrameGrayscale(Screen.Tileset.SheetPath.Absolute, location); bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect); } else { var image = SpriteBitmapCache.GetOrLoadFrame(Screen.Tileset.SheetPath.Absolute, location); bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect); } } } dc.DrawImage(bitmap, new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); }
private void button3_Click(object sender, EventArgs e) { using (Bitmap src = new Bitmap("d:\\WImageTest\\L01.png")) using (var srcLock = src.Lock()) using (Bitmap dest = new Bitmap(400, 500)) using (var dstLock = dest.Lock()) { WriteableBitmap dstWb = dstLock.GetWritableBitmap(); WriteableBitmap srcWb = srcLock.GetWritableBitmap(); int y = 0; dstWb.Clear(System.Windows.Media.Imaging.Color.FromArgb(255, 255, 255, 255)); dstWb.Blit(new Rect(10, 10, src.Width, src.Height), srcWb, new Rect(0, 0, src.Width, src.Height), WriteableBitmapExtensions.BlendMode.None ); dstWb.Blit(new Rect(100, 100, src.Width * 2, src.Height * 2), srcWb, new Rect(0, 0, src.Width, src.Height), WriteableBitmapExtensions.BlendMode.None ); dstLock.WriteAndUnlock(); dest.Save("d:\\WImageTest\\a0004.png"); } }
private void ChangeBitmap() { if (this.selectedMode == MODE_CLONE) { if (this.samplingPointValid) { int width = Math.Min(this.brushBitmap.PixelWidth, this.editedBitmap.PixelWidth); int height = Math.Min(this.brushBitmap.PixelHeight, this.editedBitmap.PixelHeight); Rect src_rect = new Rect(); src_rect.X = Math.Min(Math.Max(0, this.samplingPoint.X - width / 2), this.editedBitmap.PixelWidth - width); src_rect.Y = Math.Min(Math.Max(0, this.samplingPoint.Y - height / 2), this.editedBitmap.PixelHeight - height); src_rect.Width = width; src_rect.Height = height; Rect dst_rect = new Rect(); dst_rect.X = Math.Min(Math.Max(0, this.clonePoint.X - width / 2), this.editedBitmap.PixelWidth - width); dst_rect.Y = Math.Min(Math.Max(0, this.clonePoint.Y - height / 2), this.editedBitmap.PixelHeight - height); dst_rect.Width = width; dst_rect.Height = height; Rect brh_rect = new Rect(0, 0, width, height); WriteableBitmap brush_bitmap = new WriteableBitmap(width, height); brush_bitmap.Blit(brh_rect, this.editedBitmap, src_rect, WriteableBitmapExtensions.BlendMode.None); brush_bitmap.Blit(brh_rect, this.brushBitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Mask); this.editedBitmap.Blit(dst_rect, brush_bitmap, brh_rect, WriteableBitmapExtensions.BlendMode.Alpha); this.EditorImage.Source = this.editedBitmap; } } else if (this.selectedMode == MODE_BLUR) { int width = Math.Min(this.brushBitmap.PixelWidth, this.editedBitmap.PixelWidth); int height = Math.Min(this.brushBitmap.PixelHeight, this.editedBitmap.PixelHeight); Rect src_rect = new Rect(); src_rect.X = Math.Min(Math.Max(0, this.blurPoint.X - width / 2), this.editedBitmap.PixelWidth - width); src_rect.Y = Math.Min(Math.Max(0, this.blurPoint.Y - height / 2), this.editedBitmap.PixelHeight - height); src_rect.Width = width; src_rect.Height = height; Rect blr_rect = new Rect(0, 0, width, height); WriteableBitmap blur_bitmap = new WriteableBitmap(width, height); blur_bitmap.Blit(blr_rect, this.editedBitmap, src_rect, WriteableBitmapExtensions.BlendMode.None); blur_bitmap = blur_bitmap.Convolute(GAUSSIAN_KERNEL); this.editedBitmap.Blit(src_rect, blur_bitmap, blr_rect, WriteableBitmapExtensions.BlendMode.None); this.EditorImage.Source = this.editedBitmap; } }
private void BlitWithLayer(object sender, RoutedEventArgs e) { if (CentralMonitor.IsEnabled) { monitorImg.Source = monitor; monitor.Blit(new Rect(new Size(68, 42)), drawlayer, new Rect(new Size(68, 42))); drawlayer.Blit(new Rect(new Size(68, 42)), monitor, new Rect(new Size(68, 42))); } }
/// <summary> /// This event loads the data of the monitorbitmap into a byte array /// the bytearray is set as a property of <seealso cref="RgbLibrary.DataOut"/> class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void monitorTimer_Tick(object sender, EventArgs e) { bitmapbuffer = monitor.ToByteArray(); portWindow.data.TransferBytes = bitmapbuffer; if (ex_eff != null) { ex_eff(); } monitor.Blit(new Rect(new Size(68, 42)), filterBitmap, new Rect(new Size(68, 42)), WriteableBitmapExtensions.BlendMode.Multiply); }
public void DisplayHearts(WriteableBitmap surface) { if (WorldUser == null) { return; } int indexToUse = 0; List <int> percents = new List <int> { 0, 20, 40, 60, 80, 100 }; double myHealthPercent = ((double)WorldUser.CurrentHealth / WorldUser.MaxHealth) * 100; for (int i = 0; i <= percents.Count - 2; i += 1) { if (myHealthPercent > percents[i] && myHealthPercent <= percents[i + 1]) { indexToUse = i + 1; } } //create WriteableBitmap from image source BitmapImage heartsImage = new BitmapImage(new Uri(StageGraphics.Hearts[indexToUse], UriKind.Relative)); WriteableBitmap hearts = new WriteableBitmap(heartsImage); //Merge it to the surface at the top left surface.Blit(new Point(0, 0), hearts, new Rect(new Size((double)hearts.PixelWidth, (double)hearts.PixelHeight)), Colors.White, WriteableBitmapExtensions.BlendMode.Alpha); }
public void DisplayCoins(WriteableBitmap surface) { Bitmap coinBitmap = new Bitmap(StageGraphics.coin); Bitmap coinAndText = new Bitmap(coinBitmap.Width + 50, coinBitmap.Height); using (Graphics g = Graphics.FromImage(coinAndText)) { g.Clear(System.Drawing.Color.Transparent); g.DrawImage(coinBitmap, 0, 0, coinBitmap.Width, coinBitmap.Height); g.DrawString(WorldUser.coins.ToString(), new Font("Times New Roman", 8), Brushes.Gold, new System.Drawing.Point(coinBitmap.Width, 5)); IntPtr hBitmap = coinAndText.GetHbitmap(); try { BitmapSource Imagesource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); WriteableBitmap ImageBitmap = new WriteableBitmap(Imagesource); surface.Blit(new Point(0, 40), ImageBitmap, new Rect(new Size((double)ImageBitmap.PixelWidth, (double)ImageBitmap.PixelHeight)), Colors.White, WriteableBitmapExtensions.BlendMode.Alpha); } finally { DeleteObject(hBitmap); } } }
public void tryDrawChurchMenu(WriteableBitmap surface) { if (InChurch) { Bitmap menu = new Bitmap(StageGraphics.ChurchMenu); using (Graphics g = Graphics.FromImage(menu)) { g.DrawString(WorldUser.MaxHealth.ToString(), new Font("Times New Roman", 34), System.Drawing.Brushes.Indigo, new System.Drawing.Point(75, 190)); g.DrawString(WorldUser.MaxDamage.ToString(), new Font("Times New Roman", 34), System.Drawing.Brushes.Indigo, new System.Drawing.Point(270, 190)); IntPtr hBitmap = menu.GetHbitmap(); try { BitmapSource Imagesource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); WriteableBitmap ImageBitmap = new WriteableBitmap(Imagesource); surface.Blit(new Point(StageGraphics.WindowWidth / 2 - menu.Width / 2, 50), ImageBitmap, new Rect(new Size((double)ImageBitmap.PixelWidth, (double)ImageBitmap.PixelHeight)), Colors.White, WriteableBitmapExtensions.BlendMode.Alpha); } finally { DeleteObject(hBitmap); } } } }
public static async Task <WriteableBitmap> GetImage(string source) { WriteableBitmap image = new WriteableBitmap(250, 250); try { if (source.Contains(";")) { var speakers = source.Split(';'); int count = 0; foreach (string speaker in speakers) { var rass1 = RandomAccessStreamReference.CreateFromUri(new System.Uri(speaker, UriKind.Absolute)); IRandomAccessStream stream1 = await rass1.OpenReadAsync(); //We initialize the bitmap with height and width, but the actual size will be reset after the FromStream method! WriteableBitmap speakerImage = new WriteableBitmap(150, 150); speakerImage = await speakerImage.FromStream(stream1); int xPosition = 0; int yPosition = 0; if (count == 1 || count == 3) { yPosition = yPosition + 125; } if (count == 2 || count == 3) { xPosition = xPosition + 125; } //We use Blit to do image resizing and image merging image.Blit(new Rect() { Height = 125, Width = 125, X = xPosition, Y = yPosition }, speakerImage, new Rect() { Height = speakerImage.PixelHeight, Width = speakerImage.PixelWidth, X = 0, Y = 0 }, WriteableBitmapExtensions.BlendMode.Additive); count++; } } else { var rass1 = RandomAccessStreamReference.CreateFromUri(new System.Uri(source, UriKind.Absolute)); IRandomAccessStream stream1 = await rass1.OpenReadAsync(); //We initialize the bitmap with height and width, but the actual size will be reset after the FromStream method! image = await image.FromStream(stream1); } return(image); } catch (Exception exception) { return(image); } }
/// <summary> /// Scrolls all text up the screen by one line, then clears the last line. /// </summary> public void Scroll() { var numRowsToCopy = ScreenRows - 1; // Copy the screen data. Blit is used to ensure that any shapes (lines, points, circles, etc) are // also scrolled. var rectSize = new Size(ScreenCols * CellWidth, numRowsToCopy * CellHeight); var sourceRect = new Rect(new Point(0, CellHeight), rectSize); var destRect = new Rect(new Point(0, 0), rectSize); _wb.Blit(destRect, _wb, sourceRect, WriteableBitmapExtensions.BlendMode.None); // The text cells' metadata needs to be copied so that we know which chars, colours, etc. are where. // It's not necessary to redraw though, as the above Blit() has already done this. for (var r = 0; r < numRowsToCopy; r++) { for (var c = 0; c < ScreenCols; c++) { _cells[r, c].CopyFrom(_cells[r + 1, c], metaDataOnly: true); } } // Clear the bottom line. for (var c = 0; c < ScreenCols; c++) { _cells[ScreenRows - 1, c].Clear(Paper); } }
private void UpdateImageDisplay() { int pix_Width = 0; int pix_Height = 0; foreach (WriteableBitmap image in Images) { pix_Width += image.PixelWidth; if (pix_Height < image.PixelHeight) { pix_Height = image.PixelHeight; } } FinalImage = BitmapFactory.New(pix_Width, pix_Height); int pix_x = 0; int pix_y = 0; foreach (WriteableBitmap image in Images) { Rect imageRect = new Rect(pix_x, pix_y, image.PixelWidth, image.PixelHeight); FinalImage.Blit(imageRect, image, new Rect(0, 0, image.PixelWidth, image.PixelHeight)); pix_x += image.PixelWidth; } SpriteSheetImage.Source = FinalImage; }
private static WriteableBitmap BlitBitmaps(WriteableBitmap bitmap1, WriteableBitmap bitmap2) { bitmap1.Blit(new Windows.Foundation.Rect(0, 0, bitmap1.PixelWidth, bitmap1.PixelHeight), bitmap2, new Windows.Foundation.Rect(0, 0, bitmap2.PixelWidth, bitmap2.PixelHeight)); //merge 2 bitmaps return(bitmap1); }
private async void btnDone_Click(object sender, RoutedEventArgs e) { //var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; //canvas on display has different scaling compare to screen scaling //photo is 3264x1836 //TODO: fullscreen mode affected the aspect ratio. verify aspect ratio on machine var scaleFactor = writeableBitmap.PixelWidth / canvas.ActualWidth; var marginTop = (canvas.ActualHeight - writeableBitmap.PixelHeight / scaleFactor) / 2.0; //var scaleFactorH = 1836 / canvas.ActualHeight; foreach (Windows.UI.Xaml.Controls.Image i in canvas.Children) { double x = Canvas.GetLeft(i) * scaleFactor; double y = (Canvas.GetTop(i) - marginTop) * scaleFactor; double width = 110 * scaleFactor; double height = 110 * scaleFactor; string name = i.Name; WriteableBitmap wb = Props[Convert.ToInt32(name)].sticker.Resize((int)width, (int)height, WriteableBitmapExtensions.Interpolation.Bilinear); writeableBitmap.Blit(new Rect(x, y, width, height), wb, new Rect(0, 0, width, height)); } StorageFile editedFile = await WriteableBitmapToStorageFile(writeableBitmap, FileFormat.Jpeg); this.Frame.Navigate(typeof(UploadProgressPage)); }
/// <summary> /// Draws circle on bitmap. /// </summary> /// <param name="layer">Layer to operate on.</param> /// <param name="coordinates">Starting pixel coordinates.</param> /// <param name="color">Circle color.</param> private async void CircleAsync(Layer layer, Coordinates coordinates, Color color) { WriteableBitmap wb = layer.LayerBitmap; //Basically does the same like rectangle method, but with different shape _toolIsExecuting = true; WriteableBitmap bitmap = wb.Clone(); while (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed) { wb.Clear(); wb.Blit(new Rect(new Size(layer.Width, layer.Height)), bitmap, new Rect(new Size(layer.Width, layer.Height)), WriteableBitmapExtensions.BlendMode.Additive); if (coordinates.X > _activeCoordinates.X && coordinates.Y > _activeCoordinates.Y) { wb.DrawEllipse(_activeCoordinates.X, _activeCoordinates.Y, coordinates.X, coordinates.Y, color); } else if (coordinates.X < _activeCoordinates.X && coordinates.Y < _activeCoordinates.Y) { wb.DrawEllipse(coordinates.X, coordinates.Y, _activeCoordinates.X, _activeCoordinates.Y, color); } else if (coordinates.Y > _activeCoordinates.Y) { wb.DrawEllipse(coordinates.X, _activeCoordinates.Y, _activeCoordinates.X, coordinates.Y, color); } else { wb.DrawEllipse(_activeCoordinates.X, coordinates.Y, coordinates.X, _activeCoordinates.Y, color); } await Task.Delay(_asyncDelay); } _toolIsExecuting = false; }
/// <summary> /// Draws rectangle on bitmap /// </summary> /// <param name="layer">Layer to operate on</param> /// <param name="coordinates">Starting pixel coordinate</param> /// <param name="color">Rectangle color</param> private async void RectangleAsync(Layer layer, Coordinates coordinates, Color color) { WriteableBitmap wb = layer.LayerBitmap; _toolIsExecuting = true; WriteableBitmap writeableBitmap = wb.Clone(); while (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed) { //Two lines below are responsible for clearing last rectangle (on mouse move), to live show rectangle on bitmap wb.Clear(); wb.Blit(new Rect(new Size(layer.Width, layer.Height)), writeableBitmap, new Rect(new Size(layer.Width, layer.Height)), WriteableBitmapExtensions.BlendMode.Additive); //Those ifs are changing direction of rectangle. In other words: flips rectangle on X and Y axis when needed if (coordinates.X > _activeCoordinates.X && coordinates.Y > _activeCoordinates.Y) { wb.DrawRectangle(_activeCoordinates.X, _activeCoordinates.Y, coordinates.X, coordinates.Y, color); } else if (coordinates.X < _activeCoordinates.X && coordinates.Y < _activeCoordinates.Y) { wb.DrawRectangle(coordinates.X, coordinates.Y, _activeCoordinates.X, _activeCoordinates.Y, color); } else if (coordinates.Y > _activeCoordinates.Y) { wb.DrawRectangle(coordinates.X, _activeCoordinates.Y, _activeCoordinates.X, coordinates.Y, color); } else { wb.DrawRectangle(_activeCoordinates.X, coordinates.Y, coordinates.X, _activeCoordinates.Y, color); } await Task.Delay(_asyncDelay); } _toolIsExecuting = false; }
async Task <WriteableBitmap> StitchImages(WriteableBitmap[] bitmaps) { double offset = 0; // counter for our loop below var resizedImages = // collection of our captured images (from image in this.capturedImages select image.Resize(THUMB_WIDTH, THUMB_HEIGHT, WriteableBitmapExtensions.Interpolation.Bilinear)).Reverse(); // initialize the 'canvas' for the final stitched image -> set background to white finalStitch.Clear(Windows.UI.Colors.White); // log this method EventSource.Log.Debug("StitchImages()"); foreach (WriteableBitmap image in resizedImages) { Point dest = new Point(BORDER, (THUMB_HEIGHT * offset) + BORDER + BORDER * offset); Rect sourceImageRect = new Rect(new Point(0, 0), new Point(THUMB_WIDTH, THUMB_HEIGHT)); finalStitch.Blit(dest, image, sourceImageRect, Windows.UI.Colors.White, WriteableBitmapExtensions.BlendMode.None); offset++; } // set our file name finalStitchName = await SaveBitmapFile(finalStitch); return(finalStitch); }
public void ExpandingObjects_execute() { writeableBmp.Clear(); using (writeableBmp.GetBitmapContext()) { for (int i = 0; i < amount; i++) { expandingObject[i].expand(); switch (selected_obj) { case "ellipse": writeableBmp.DrawEllipse(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "filled ellipse": writeableBmp.FillEllipse(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "rectangle": writeableBmp.DrawRectangle(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "filled rectangle": writeableBmp.FillRectangle(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; } } } writeableBmp.Blit(new Rect(new Size(68, 42)), writeableBmp, new Rect(new Size(68, 42)), WriteableBitmapExtensions.BlendMode.Mask); }
private void ExtractImage(List <WriteableBitmap> tempTiles, BitmapSource image, int spacing, int offset, IProgress <ProgressDialogState> progress = null) { var sourceImage = BitmapFactory.ConvertToPbgra32Format(image); var jump = 16 + spacing; var totalTiles = ((image.PixelWidth - offset) / jump) * ((image.PixelHeight - offset) / jump); var currentTile = 0; for (var y = offset; y < image.PixelHeight; y += jump) { for (var x = offset; x < image.PixelWidth; x += jump) { var tileImage = new WriteableBitmap(16, 16, 96, 96, PixelFormats.Pbgra32, null); tileImage.Blit(new System.Windows.Rect(0, 0, 16, 16), sourceImage, new System.Windows.Rect(x, y, 16, 16)); tempTiles.Add(tileImage); currentTile++; if (progress != null) { progress.Report(new ProgressDialogState() { ProgressPercentage = currentTile * 100 / totalTiles, Description = string.Format("Extracting {0} / {1}", currentTile, totalTiles) }); } } } }
public static void WriteTextToBitmap(WriteableBitmap bm, List <Tuple <String, Point, int> > data) { Bitmap bmap; using (MemoryStream outStream = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create((BitmapSource)bm)); enc.Save(outStream); bmap = new System.Drawing.Bitmap(outStream); } using (Graphics g = Graphics.FromImage(bmap)) { Font font; foreach (var item in data) { font = new Font("Times New Roman", item.Item3); g.DrawString(item.Item1, font, Brushes.Black, item.Item2); } IntPtr hBmap = bmap.GetHbitmap(); try { BitmapSource Bsource = Imaging.CreateBitmapSourceFromHBitmap(hBmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); WriteableBitmap NewBmap = new WriteableBitmap(Bsource); bm.Blit(new System.Windows.Point(0, 0), NewBmap, new Rect(new Size((double)NewBmap.PixelWidth, (double)NewBmap.PixelHeight)), Colors.White, WriteableBitmapExtensions.BlendMode.Alpha); } finally { } } }
public override void Draw(WriteableBitmap surface) { Rect sourceRect = new Rect(animoffset * spriteSizeX, 0, spriteSizeX, spriteSizeY); Rect destRect = new Rect((int)Position.X - spriteSizeX * Scale.X / 2, (int)Position.Y - spriteSizeY * Scale.Y / 2, spriteSizeX * Scale.X, spriteSizeY * Scale.Y); surface.Blit(destRect, spriteSheet, sourceRect); }
public void Update(double elapsedSeconds) { elapsedRemainder += elapsedSeconds; while (elapsedRemainder > updateInterval) { elapsedRemainder -= updateInterval; CreateParticle(); particleColor.H += .1; particleColor.H = particleColor.H % 255; for (int i = Particles.Count - 1; i >= 0; i--) { Particle p = Particles[i]; p.Update(updateInterval); if (p.Color.A == 0) { Particles.Remove(p); } } } using (TargetBitmap.GetBitmapContext()) { using (ParticleBitmap.GetBitmapContext()) { for (int i = 0; i < Particles.Count; i++) { Particle p = Particles[i]; TargetBitmap.Blit(p.Position, ParticleBitmap, sourceRect, p.Color, WriteableBitmapExtensions.BlendMode.Additive); } } } }
private static void WriteImageToBitmap(WriteableBitmap resultWb1, string smallImageUri, int currentXOffset, int currentYOffset, int widthOfOneItemInPixels, int heightOfOneItemInPixels) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.CreateOptions = BitmapCreateOptions.None; bitmapImage.DecodePixelType = DecodePixelType.Physical; bitmapImage.DecodePixelWidth = widthOfOneItemInPixels; bitmapImage.DecodePixelHeight = heightOfOneItemInPixels; try { Stream stream = Application.GetResourceStream(new Uri(smallImageUri, UriKind.Relative)).Stream; bitmapImage.SetSource(stream); WriteableBitmap source = new WriteableBitmap((BitmapSource)bitmapImage); resultWb1.Blit(new Rect() { X = (double)currentXOffset, Y = (double)currentYOffset, Width = (double)widthOfOneItemInPixels, Height = (double)heightOfOneItemInPixels }, source, new Rect() { Width = (double)widthOfOneItemInPixels, Height = (double)heightOfOneItemInPixels }); } catch { } }
/// <summary> /// Copies the pixels of the tile at the given index into the target bitmap at the given location. The location is given in pixel units. /// </summary> /// <param name="tileIndex">The tile index. Zero-based.</param> /// <param name="target">The target <see cref="WriteableBitmap"/>.</param> /// <param name="targetX">The target X coordinate, in pixels.</param> /// <param name="targetY">The target Y coordinate, in pixels.</param> public void BlitTo(int tileIndex, WriteableBitmap target, int targetX, int targetY) { var(row, column) = this.FromIndex(tileIndex); var sourceRect = new Rect(new Point(column * this.tileSize.Width, row * this.tileSize.Height), this.tileSize); target?.Blit(new Rect(new Point(targetX, targetY), this.tileSize), this.bitmap, sourceRect); }
/// <summary> /// Method to generate a WriteableBitmap from list of card Ids. /// </summary> /// <param name="strDeckCardIds">List of strings representing card Ids.</param> /// <returns>A WriteableBitmap representing the combined image of cards.</returns> private async Task <WriteableBitmap> generateWriteableBitmapForDeck(List <string> strDeckCardIds) { // Get a list of unique card IDs as the final image should only have each card appear once. strDeckCardIds = strDeckCardIds.Distinct().ToList(); // Calculate final image size based on how many cards we have in our list. int intTotalCards = strDeckCardIds.Count; double cols = 5; int rows = (int)Math.Ceiling(intTotalCards / cols); // Create out empty WriteableBitmap. var finalWriteableBitmap = new WriteableBitmap((int)cols * 421, rows * 614); // Track which column and row we are in. int intColumn = 0; int intRow = 0; // Constant string representing base url of card image. const string strCardFrontBaseUrl = "https://ygoprodeck.com/pics/"; // Iterate over the list of card Ids. for (int i = 0; i < strDeckCardIds.Count; i++) { string strDeckCard = strDeckCardIds[i]; // Create a WriteableBitmap to hold picture from YGOPro. var writeableBitmap = new WriteableBitmap(1, 1); using (HttpClient client = new HttpClient()) { using (HttpResponseMessage response = await client.GetAsync(strCardFrontBaseUrl + strDeckCard + ".jpg")) { var image = await BitmapFactory.FromStream(await response.Content.ReadAsStreamAsync()); byte[] pixels; Guid BitmapEncoderGuid = BitmapEncoder.JpegEncoderId; using (Stream stream = image.PixelBuffer.AsStream()) { pixels = new byte[(uint)stream.Length]; await stream.ReadAsync(pixels, 0, pixels.Length); } // Specify x and y of where to insert into final WriteableImage from column and row. int x = intColumn * 421; int y = intRow * 614; // Combine images. finalWriteableBitmap.Blit(new Rect(x, y, image.PixelWidth, image.PixelHeight), image, new Rect(0, 0, image.PixelWidth, image.PixelHeight), WriteableBitmapExtensions.BlendMode.None); if (++intColumn >= cols) { // Reset column and increment row intColumn = 0; intRow++; } } } } return(finalWriteableBitmap); }
/// <summary> /// Not working yet. /// </summary> /// <param name="bitmap"></param> /// <param name="pixelCoordinates"></param> /// <param name="color"></param> /// <param name="highlightThickness"></param> public static void HighlightPixel(WriteableBitmap bitmap, Coordinates pixelCoordinates, Color color, int highlightThickness) { bitmap.Clear(); bitmap.Blit(new Rect(new Size(bitmap.Width, bitmap.Height)), bitmap, new Rect(new Size(bitmap.Width, bitmap.Height)), WriteableBitmapExtensions.BlendMode.Additive); DCords centerCords = CalculateThicknessCenter(pixelCoordinates, highlightThickness); bitmap.FillRectangle(centerCords.Coords1.X, centerCords.Coords1.Y, centerCords.Coords2.X, centerCords.Coords2.Y, color); }
public WriteableBitmap MixAdd(WriteableBitmap inA, WriteableBitmap inB) { Rect cRect = new Rect(new Size(inA.Width, inA.Height)); inA.Blit(cRect, inB, cRect, WriteableBitmapExtensions.BlendMode.Additive); return(inA); }
private WriteableBitmap MixMultiply(WriteableBitmap inA, WriteableBitmap inB) { Rect cRect = new Rect(new Size(inA.Width, inA.Height)); inA.Blit(cRect, inB, cRect, WriteableBitmapExtensions.BlendMode.Multiply); return(inA); }
public static void Colorize(this WriteableBitmap bitmap, System.Windows.Media.Color color) { var tempBitmap = BitmapFactory.New(bitmap.PixelWidth, bitmap.PixelHeight); tempBitmap.FillRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelHeight, color); bitmap.Blit(new System.Windows.Point(0, 0), tempBitmap, new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), Colors.White, WriteableBitmapExtensions.BlendMode.Multiply); }