I'm trying to paste images from an external source (Paint.NET in my test), but it gives a D3DImage which I don't know how to convert to Bitmap.
How to do that?
A D3DImage, although it is a strange beast, is an ImageSource, so you can use as the Source for an Image and an Image is a Visual so you can use RenderTargetBitmap on it. There is sample code in the RenderTargetBitmap documentation that actually copies the bitmap from the Visual to another Image on same page:
RenderTargetBitmap Class
Related
I have searched around and found that most of the answers convert a WriteableBitmap to a System.Drawing.Bitmap. I am currently thinking of using WriteableBitmapEx's Blitz() function to overlay a bitmap with text onto the existing bitmap, but I don't really find functions that return WriteableBitmap.
Is there a easy way to draw text?
I managed to use the WriteableBitmapEx DrawString() method to achieve this directly.
Unfortunately it is not inside the Nuget Packages so it has to be compiled from the source of another project:
https://writeablebitmapex.codeplex.com/discussions/579148
https://fastwpfgrid.codeplex.com/SourceControl/latest#WriteableBitmapEx/LetterGlyphTool.cs
I've not fully understand the basics of Bit blit bitmaps.
I'm using the WriteableBitmapEx framework (WPF). My bitmap represents a map and what I wanna achieve is to copy a (moving) symbol into that map.
For actual copying, I use the function Blit:
_bitmap.Blit(myObject.Value.Location.ToWindowsPoint(), symbol, rect, Colors.Cyan,
WriteableBitmapExtensions.BlendMode.Additive);
where symbol is a png image(transparent background).
This works in prinicpal but I do not understand how the color (Colors.Cyan) is applied by the blend mode. I've tried out all available blend modes but I've not succeeded in getting Cyan as the color of the symbol or I got the color but then the transparent background was also copied to the source bitmap (black background).
Is 'Bliting' the wrong approach for my use case?
Thanks.
A much easier approach is to use images (corresponding WPF ui element) and layer it above the bitmap. This has also the advantage that you can move the image without redrawing the bitmap at all.
Does anyone know how to apply brightness and contrast control to an Image in silverlight 5? Maybe using UIElement.Effect? I don't need to modify/save the image, just change how it is displayed.
Use a WriteableBitmap as source for your image and then apply a brightness/contrast formula on every pixel of the WriteableBitmap.
You need to call Invalidate() on your bitmap instance after you have changed the pixels.
I ended up using a Custom Pixel Shader. Shazzam has a contrast adjust custom pixel shader in it's pre-installed samples. The beauty of this is that it works in both WPF and silverlight.
I want to 'grab' the image of a control on my winforms dialog. I can access the 'graphics' context for the control using:
MyControl.CreateGraphics()
But how do i copy a rectangle from that graphics context to an image, or a bitmap, or call getpixel on it?
Thanks a lot.
I think MyControl.DrawToBitmap is the way to go:
Bitmap bmp = new Bitmap(MyControl.Width, MyControl.Height);
MyControl.DrawToBitmap(bmp, MyControl.ClientRectangle);
If you need to get the pixels then use Bitmap.GetPixel or Bitmap.LockBits
I am using ImageTool's PNG encoder to create an image.
I have a Grid that contains multiple TextBlocks, each TextBlock contains dynamic text.
When I create a WriteableBitmap from the grid containing the TextBlocks, I then use ImageTool's encoder to convert the WriteableBitmap to a PNG image.
All works well, however, when I view the PNG image (am saving the file to the hard drive for testing purposes) - the text looks slightly blurred. Is this an issue with the encoder or the WriteableBitmap class? And - has anyone experienced this before and are there workarounds?
Thanks.
I'm a part of ImageTool project but I'm playing as a tester since I'm using this library in one of my project... If you can create a sample then you can probably show us so that we can test in our machine.
You can also try with Joe Stegman's encoder or fJCore JPEG encoder.