system.drawing

Remove a round transparent section of an Image c#

ぐ巨炮叔叔 提交于 2019-12-11 02:24:25
问题 I am creating an Circle on a bitmap but want to have a hole in it. After serching for half an hour I only found ways to crop an image to a circle. The hard thing is, that the hole in the middle should be transparent as the rest of the Image. This is the base image and the yellow circle represents the transparent area that should be added. Thanks for any kind of help. 回答1: The start is simple: Create a transparent bitmap by doing a g.Clear(Color.Transparent) and then draw/fill a circle in a

Write text to image with indexed pixel format

拈花ヽ惹草 提交于 2019-12-11 00:56:29
问题 I have monochrome TIFF files (1 bpp) that I would like to write text to. When I load them into System.Drawing.Image, and try to instantiate a Graphics object from that image, I receive the error, "A Graphics object cannot be created from an image that has an indexed pixel format." I can convert the images to a non-indexed format, such as JPEG, but then the resulting image size is very large. I would like to accomplish this while keeping the image size down. How can I write text onto these

Moving Object with Paint Event

若如初见. 提交于 2019-12-10 23:38:40
问题 I have a test tomorrow, and we must use the paint event to redraw our objects, we may not use a timer. As the MSDN says: "The Paint event is raised when the control is redrawn." , but that,occurs for my known, only when the form is minimized, or got invisible and back visible. My code: public partial class Form1 : Form { public Graphics drawArea; public int xPos, yPos; public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { drawArea = e.Graphics;

Disposing a static brush

你离开我真会死。 提交于 2019-12-10 21:37:56
问题 I'm writing a biorhythm app. To test it i have a form with a Button and a PictureBox. When I click on the button i do myPictureBox.Image = GetBiorhythm2(); Which runs ok for the first time, but on the second click it causes the following exception: System.ArgumentException: Parameter is not valid. at System.Drawing.Graphics.CheckErrorStatus at System.Drawing.Graphics.FillEllipse at Larifari.Biorhythm.Biorhythm.GetBiorhythm2 in c:\delo\Horoskop\Biorhythm.cs:line 157 at Larifari.test

Saving a one color bitmap with alpha channel in Windows Forms saves a different (wrong) color

依然范特西╮ 提交于 2019-12-10 21:28:35
问题 In C#, .NET 2.0, Windows Forms, Visual Studio Express 2010, I'm saving an image made of the same color: Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bitmap)) { Brush brush = new SolidBrush(color); graphics.FillRectangle(brush, 0, 0, width, height); brush.Dispose(); } bitmap.Save("test.png"); bitmap.Save("test.bmp"); If I'm using, for example Color [A=153, R=193, G=204, B=17] or #C1CC11 after I'm saving the image and open

Bitmap.Save “Object is currently in use elsewhere” Threading Issue

前提是你 提交于 2019-12-10 20:46:34
问题 I have some code like this: public void SaveImage(int Counter) { var task = Task.Factory.StartNew(() => { var image = FinalImage; if (image != null) { image.Save(FinalImageSaveLocation + "test" + Counter + ".bmp"); } }, TaskCreationOptions.PreferFairness); } I have a for loop creating x amount of images using similar code below: for(int i = 0; i < 100; i++) { Pencil.DrawImage(image, x, y); //Pencil is created at a initialisation stage SaveImage(i); //by Pencil = Graphics.FromImage(FinalImage)

Using GraphicsMagick in Unity3D

大憨熊 提交于 2019-12-10 17:56:13
问题 I'm looking for an alternative to using the System.Drawing in Unity3D, since apparently Unity doesn't support it. I'd like to simply draw some lines on a texture. But I want options such as line width and edge rounding, which are fairly complex. GraphicsMagick seemed perfect, plus it's free. So here's the steps I've already taken: 1) I changed my playersettings to use api compatability level 2.0, not "subset". 2) I downloaded GraphicsMagick .Net 2.0 x64 wrapper, extracted the dll. 3) Right

Using WIC to Quickly Create Scaled Down Bitmap that honors EXIF Orientation Tag

懵懂的女人 提交于 2019-12-10 17:09:17
问题 I'm looking for the fastest way to create scaled down bitmap that honors EXIF orientation tag Ref :https://weblogs.asp.net/bleroy/the-fastest-way-to-resize-images-from-asp-net-and-it-s-more-supported-ish Currently i use the following code to create a Bitmap that honors EXIF Orientation tag static Bitmap FixImageOrientation(Bitmap srce) { const int ExifOrientationId = 0x112; // Read orientation tag if (!srce.PropertyIdList.Contains(ExifOrientationId)) return srce; var prop = srce

DrawImage scales original image

。_饼干妹妹 提交于 2019-12-10 15:55:00
问题 I am stitching several images together vertically and horizontally to create one bigger image (in which the total width and height are the sum of the widths and heights of the individual images) using Bitmap and System.Drawing.Graphics in C#. The size of the individual images are 256 px by 256 px. When I use DrawImage from System.Drawing.Graphics , why do I get a scaled and/or zoomed in version of the original image? Here is the original image: When I retrieve the image programmatically and

Convert RenderTargetBitmap into System.Drawing.Image

最后都变了- 提交于 2019-12-10 14:59:19
问题 I have 3D WPF visual that I want to pass into an Excel cell (via clipboard buffer). With "normal" BMP images it works but I do not know how to convert a RenderTargetBitmap . My code looks like this: System.Windows.Media.Imaging.RenderTargetBitmap renderTarget = myParent.GetViewPortAsImage(DiagramSizeX, DiagramSizeY); System.Windows.Controls.Image myImage = new System.Windows.Controls.Image(); myImage.Source = renderTarget; System.Drawing.Bitmap pg = new System.Drawing.Bitmap(DiagramSizeX,