system.drawing

How to set multiple FontStyles when instantiating a font?

♀尐吖头ヾ 提交于 2019-12-01 03:00:18
In looking at the constructors for the System.Drawing.Font class there is a parameter to pass in one of the FontStyles defined in the System.Drawing.FontStyle enum. ie. Bold Italic Regular Underline and there are boolean properties for Bold, Italic, Underline etc. in the instantiated object, but they are read only. What if I want to define my font to have multiple styles like Bold and Underline? How can I do this? The FontStyle enum is a Flags enum. This means that its members are all powers of two, allowing you to combine them using a binary OR. For example, if you want bold and underline,

WPF v/s System.Drawing

半腔热情 提交于 2019-12-01 00:14:35
I have to code a simple control in .Net that draws geometry that looks like following image and the geometry doesn't get any more complex than shown in this image, i.e. it will be a few filled polygons and some dashed lines. This is not a static image however, that is drawn once and forgotten. The dimensions of the geometry can be changed by the user which will have to be reflected in the drawing by updating it. My senior says I should use WPF for drawing. My question is whether WPF is overkill for this kind of work and will System.Drawing suffice? While WPF probably does have drawing

InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images

独自空忆成欢 提交于 2019-11-30 23:50:38
问题 Using some pretty stock standard C# code to resize an image, and place it on a coloured background Image imgToResize = Image.FromFile(@"Dejeuner.jpg"); Size size = new Size(768, 1024); Bitmap b = new Bitmap(size.Width, size.Height); Graphics g = Graphics.FromImage((Image)b); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.FillRectangle(Brushes.Green, 0, 0, size.Width, size.Height); g.DrawImage(imgToResize, new Rectangle(0,150,768, 570)); b.Save("sized_HighQualityBicubic.jpg");

Cannot render image to HttpContext.Response.OutputStream

北慕城南 提交于 2019-11-30 20:11:20
Basically I am trying to render a simple image in an ASP.NET handler: public void ProcessRequest (HttpContext context) { Bitmap image = new Bitmap(16, 16); Graphics graph = Graphics.FromImage(image); graph.FillEllipse(Brushes.Green, 0, 0, 16, 16); context.Response.ContentType = "image/png"; image.Save(context.Response.OutputStream, ImageFormat.Png); } But I get the following exception: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) The solution is to use

How can I tell if two polygons intersect?

久未见 提交于 2019-11-30 19:32:45
Imagine I have the coordinate of 4 points that form a polygon. These points are represented using PointF in C#. If I have 2 polygons (using 8 points), how can I tell if they intersect? Rectangle class has a method called IntersectsWith but I couldn't find something similar for GraphicsPath or Region. Any advice would be greatly appreciated. Mosh Patrick Klug As Charlie already pointed out you can use the Separating Axis theorem. Check out this article for a C# implementation and example of polygon collision detection. I have also answered this question here which deals with 2D collision in C#.

WPF v/s System.Drawing

久未见 提交于 2019-11-30 18:34:00
问题 I have to code a simple control in .Net that draws geometry that looks like following image and the geometry doesn't get any more complex than shown in this image, i.e. it will be a few filled polygons and some dashed lines. This is not a static image however, that is drawn once and forgotten. The dimensions of the geometry can be changed by the user which will have to be reflected in the drawing by updating it. My senior says I should use WPF for drawing. My question is whether WPF is

C# - Base64 byte array to Image FAILS no matter what I try

ぃ、小莉子 提交于 2019-11-30 16:05:00
问题 I'm having trouble creating an Image/Bitmap object in C# from a base64 encoded byte array. Here's what I'm dealing with: I have a frontend where a user can crop an image. When the user selects an image via an input[type=file] , my javascript code uses HTML5's FileReader to save the DataUrl (base64 string) to a hidden field , that is posted along with the crop coordinates and dimensions, and everything else in that form . The essence: base64 data, if you want to test yourself: http:/

Does the .Net Color struct use an HSB or HSL colour space?

那年仲夏 提交于 2019-11-30 14:58:41
问题 As I understand it HSL and HSB colour spaces are very similar, both use the same 0-360 colour wheel for hue and the same 0-1 value for saturation. The one difference between them is that in the HSB model you have brightness, where 0 is black and 1 is the colour at full intensity, while in HSL you have lightness/luminosity, where 0 is still black but 1 is white. The .net Color struct uses the RGB space, but has GetHue() , GetSaturation() and GetBrightness() functions. The documentation here is

Convert Pixels to Inches and vice versa in C#

我与影子孤独终老i 提交于 2019-11-30 13:47:58
I am looking to convert pixes to inches and vice versa. I understand that I need DPI, but I am not sure how to get this information (e.g. I don't have the Graphics object, so that's not an option). Is there a way? On a video device, any answer to this question is typically not very accurate. The easiest example to use to see why this is the case is a projector. The output resolution is, say, 1024x768, but the DPI varies by how far away the screen is from the projector apeture. WPF, for example, always assumes 96 DPI on a video device. Presuming you still need an answer, regardless of the

Does the .Net Color struct use an HSB or HSL colour space?

断了今生、忘了曾经 提交于 2019-11-30 12:43:18
As I understand it HSL and HSB colour spaces are very similar, both use the same 0-360 colour wheel for hue and the same 0-1 value for saturation. The one difference between them is that in the HSB model you have brightness, where 0 is black and 1 is the colour at full intensity, while in HSL you have lightness/luminosity, where 0 is still black but 1 is white. The .net Color struct uses the RGB space, but has GetHue() , GetSaturation() and GetBrightness() functions. The documentation here is confusing. For GetBrightness() : /// <summary>Gets the hue-saturation-brightness (HSB) brightness