system.drawing

GDI+ generic error saving bitmap created from memory using LockBits

无人久伴 提交于 2019-12-17 20:21:19
问题 The GDI+ generic error when saving a bitmap is obviously a common problem according to my research here on SO and the web. Given following simplified snippet: byte[] bytes = new byte[2048 * 2048 * 2]; for (int i = 0; i < bytes.Length; i++) { // set random or constant pixel data, whatever you want } Bitmap bmp = new Bitmap(2048, 2048, PixelFormat.Format16bppGrayScale); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 2048, 2048), ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime

How can I iterate through each pixel in a .gif image?

試著忘記壹切 提交于 2019-12-17 18:28:54
问题 I need to step through a .gif image and determine the RGB value of each pixel, x and y coordinates. Can someone give me an overview of how I can accomplish this? (methodology, which namespaces to use, etc.) 回答1: This is a complete example with both methods, using LockBits() and GetPixel(). Besides the trust issues with LockBits() things can easily get hairy. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace BitmapReader {

HSV triangle in C# [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 03:35:48
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . For my assignment I need to make to make a color picker that looks like this: I've got the wheel part but can't figure out how to draw the triangle. 回答1: using System.Drawing; using System.Drawing.Imaging; void Main() { double hue = 3.3; double sat = 0.4; double val = 0.9; var

.NET System.Drawing.Font - Get Available Sizes and Styles

非 Y 不嫁゛ 提交于 2019-12-14 03:21:30
问题 I have one combo that allows user to select a font name. The 2nd is supposed to show available sizes of the font. The 3rd has to show available styles. Question: how can I retrieve the sizes and styles selected System.Drawing.Font supports? 回答1: You could use the InstalledFontCollection class to retrieve the available fonts and then enumerate them as shown in this MSDN article. InstalledFontCollection installedFontCollection = new InstalledFontCollection(); // Get the array of FontFamily

Convert a 24 bit in memory image to indexed color

空扰寡人 提交于 2019-12-14 02:12:42
问题 I have an image that I have created in memory as Format24bppRgb. I save this as a PNG and it is 24kb. If I save the same image with photoshop as a 24bit PNG it comes to about the same size, but if i save it as an 8bit PNG with only 32 colors it goes down to 5kb. How can I create an indexed version of a PNG file using C# / GDI+ / System.Drawing ? I'm having a hard time finding any answers to this question that don't just apply to grayscale images or require an external library. is it not

degree rotation on triangle without changing position using C# windows application?

。_饼干妹妹 提交于 2019-12-13 10:55:36
问题 private void panel1_Paint(object sender, PaintEventArgs e) { Pen myPen = new Pen(Color.Blue, 1); Pen myPen2 = new Pen(Color.Red, 1); Point[] array = { new Point(639, 75), new Point(606, 124), new oint(664, 123) }; matrix.TransformPoints(array); e.Graphics.Transform = matrix; e.Graphics.RotateTransform(ang, MatrixOrder.Append); myPen2.RotateTransform(ang, MatrixOrder.Append); e.Graphics.DrawPolygon(myPen2, array); } I'm using Visual Studio 2010. The above code should be for drawing a triangle

How to assign System.Drawing.Color to Microsoft.Office.Interop.Excel.ColorFormat

流过昼夜 提交于 2019-12-13 05:25:18
问题 Sample code as follow, Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor = System.Drawing.Color.Red; Return an error. Cannot implicitly convert type, one is a Struct, the other is ColorFormat. ForeColor.RGB is Int type, I can only get 3 ints from Color.Red.R, Color.Red.G and Color.Red.B. How to assign the color I want to ForeColor property? 回答1: Try RGB property ForeColor.RGB E.g. Chart.SerialsCollection(1).Point(1).Format.Fill.ForeColor.RGB = System.Drawing.Color.Red.ToArgb(); 回答2:

Enlarging an image without blurring by taking one pixel and turning it into four on a new image with different dimensions

心不动则不痛 提交于 2019-12-13 02:20:49
问题 I have previously written an image enlarger algorithm that enlarges images without blurring by doubling the image size and making a single pixel into four pixels on the new image. This was originally built for 500x500 pixel images and it worked absolutely fine but now I need to use it for an image that has a different width and height. I have tried changing the values but I cannot get it to work and there maybe something missing but I don't know. Can someone help fix this so it works with

System.Drawing objects unmanaged resource disposing

偶尔善良 提交于 2019-12-12 23:15:52
问题 I have the following code: using System.Drawing; ... Graphics _graphics = Graphics.FromImage(...) ... public void Draw(Stream stream, Rectangle rect, Color color) { _graphics.FillRectangle(new SolidBrush(Color), 0, 0, Width, Height); _graphics.DrawImage(new Bitmap(stream), rect); } Should I surround the drawImage with using on new Bitmap(...) ? Same question on the new SolidBrush(...) 回答1: Yes, you should wrap them in using statements. Also you should ensure that the Dispose methods is

System.Drawing - Parameter is not valid

孤者浪人 提交于 2019-12-12 11:35:53
问题 After some more testing I've found that this problem may be due to the images somehow not being loaded in time to be cloned into bitmaps and displayed. Is this possible or no? NOTE: Yes, there are other questions with this error in the title, but from a bit of a research it seems to be an ambiguous error with many possible causes. I haven't found any questions with the same scenario as mine. I'm getting the following error. System.ArgumentException was unhandled HResult=-2147024809 Message