system.drawing

How do you Draw Transparent Image using System.Drawing?

江枫思渺然 提交于 2019-11-30 08:25:59
问题 I'm trying to return a transparent GIF from an .aspx page for display within a web page. I am trying to get the image to have transparency, but I just keep getting Black being where the image should be Transparent. Does anyone know what I'm doing wrong? Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Me.Load '' Change the response headers to output a GIF image. Response.Clear() Response.ContentType = "image/gif" Dim width = 110 Dim height = width ''

Silverlight 4.0: How to convert byte[] to image?

只愿长相守 提交于 2019-11-30 06:53:09
public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length); System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true); return image; } I want to convert byte[] to image, however System.Drawing.Image is not supported in Silverlight. Any alternative? You need to create an ImageSource and assign that to an Image control or use an ImageBrush to set on the

Make +y UP, Move Origin C# System.Drawing.Graphics

廉价感情. 提交于 2019-11-30 04:44:57
问题 I want the origin to be at the center of my window. ______________ | ^ | | | | | o----->| | | |____________| .NET wants it to be in the top left hand corner. _____________> | | | | | | | | V____________| Dot net and I are trying to get along.. Does anyone know how to do this in C# just using the Graphics object? Graphics.TranslateTransform doesn't do it since it leaves the coordinates flipped upside down. Combining this Graphics.ScaleTransform(1,-1) isn't satisfactory either since that makes

Cannot render image to HttpContext.Response.OutputStream

我只是一个虾纸丫 提交于 2019-11-30 04:20:43
问题 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

How can I tell if two polygons intersect?

大兔子大兔子 提交于 2019-11-30 03:43:50
问题 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 回答1: As Charlie already pointed out you can use the Separating Axis theorem. Check out this article for a C# implementation and example of polygon

How to set multiple FontStyles when instantiating a font?

时光毁灭记忆、已成空白 提交于 2019-11-30 00:48:40
问题 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? 回答1: The FontStyle enum is a Flags enum. This means that its members are all

Why is DarkGray lighter than Gray?

。_饼干妹妹 提交于 2019-11-29 20:12:46
Simple curiosity here, tinged with some practical concerns because I get caught out by this occasionally. How come Color.DarkGray is lighter than Color.Gray ? Peter Wikipedia has some information on the subject . It sounds like a lot of the named color definitions come from X Windows System. On X, "Gray" is actually closer to "Silver". However, the W3C defined Gray (more appropriately?) as RGB 50%. Here's some more Wikipedia on the subject: Perhaps most unusual of the color clashes between X11 and W3C is the case of "Gray" and its variants. In HTML, "Gray" is specifically reserved for the 128

Justifying text using DrawString in C#

匆匆过客 提交于 2019-11-29 14:18:28
I'm drawing text on a System.Drawing.Graphics object. I'm using the DrawString method, with the text string, a Font , a Brush , a bounding RectangleF , and a StringFormat as arguments. Looking into StringFormat , I've found that I can set it's Alignment property to Near , Center or Far . However I haven't found a way to set it to Justified. How can I achieve this? Thank you for your help! There is no built-in way to do it. Some work-arounds are mentioned on this thread: http://social.msdn.microsoft.com/Forums/zh/winforms/thread/aebc7ac3-4732-4175-a95e-623fda65140e They suggest using an

C# Drawstring Letter Spacing

自古美人都是妖i 提交于 2019-11-29 13:33:38
Is is somehow possible to control letter spacing when using Graphics.DrawString? I cannot find any overload to DrawString or Font that would allow me to do so. g.DrawString("MyString", new Font("Courier", 44, GraphicsUnit.Pixel), Brushes.Black, new PointF(262, 638)); By letter spacing I mean the distance between letters. With spacing MyString could look like M y S t r i n g if I added enough space. That's not supported out of the box. You'll either have to draw each letter individually (hard to get that right) or insert spaces in the string yourself. You can stretch the letters by using

Drawing a line in Winforms

拈花ヽ惹草 提交于 2019-11-29 10:40:45
I am having trouble drawing a line within a group box in a simple windows form. here is my code: public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); DrawLShapeLine(groupBox1.CreateGraphics(), 10, 10, 20, 40); } public void DrawLShapeLine(System.Drawing.Graphics g, int intMarginLeft, int intMarginTop, int intWidth, int intHeight) { Pen myPen = new Pen(Color.Black); myPen.Width = 2; // Create array of points that define lines to draw. int marginleft = intMarginLeft; int marginTop = intMarginTop; int