gdi+

Resize image gdi+ graphics .net

风格不统一 提交于 2019-12-17 13:32:09
问题 I have this method for shrinking down an image for a website that I'm working on: static byte[] createSmallerImage( BlogPhoto blogPhoto, int newMaxWidth, int newMaxHeight) { Image img; using (MemoryStream originalImage = new MemoryStream(blogPhoto.BlogPhotoImage)) { img = Image.FromStream(originalImage); } int newWidth; int newHeight; byte[] arr; if (img.Width > img.Height) { if (img.Width <= newMaxWidth) { using (MemoryStream thumbStr = new MemoryStream()) { img.Save(thumbStr, ImageFormat

How can I take a screenshot and save it as JPEG on Windows?

China☆狼群 提交于 2019-12-17 10:33:06
问题 I'm trying to find a (somewhat) easy way to take a screenshot on window and save the resulting HBITMAP as a JPEG. The tricky part here is that since the code is in C I can't use GDI+ and since the code is a module for a bigger program I can't neither use an external lib (like libjpeg). This code takes a screenshot and returns a HBITMAP. Saving that bitmap into a file is easy. the problem is that the bitmap is 2 or 3mb. HDC hDCMem = CreateCompatibleDC(NULL); HBITMAP hBmp; RECT rect; HDC hDC;

How to eliminate flicker in Windows.Forms custom control when scrolling?

◇◆丶佛笑我妖孽 提交于 2019-12-17 09:51:57
问题 I want to create a custom control in C#. But every time I have to fully redraw my control, it flickers, even if I use double buffering (drawing to an Image first, and blitting that). How do I eliminate flicker when I have to fully redraw? 回答1: You could try putting the following in your constructor after the InitiliseComponent call. SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); EDIT: If you're giving this a go, if you can,

How can I tell if a point belongs to a certain line?

元气小坏坏 提交于 2019-12-17 09:37:21
问题 How can I tell if a point belongs to a certain line? Examples are appreciated, if possible. 回答1: In the simplest form, just plug the coordinates into the line equation and check for equality. Given: Point p (X=4, Y=5) Line l (Slope=1, YIntersect=1) Plug in X and Y: Y = Slope * X + YIntersect => 5 = 1 * 4 + 1 => 5 = 5 So yes, the point is on the line. If your lines are represented in (X1,Y1),(X2,Y2) form, then you can calculate slope with: Slope = (y1 - y2) / (x1-x2) And then get the Y

DrawImage resized image too small

白昼怎懂夜的黑 提交于 2019-12-17 06:55:09
问题 When I draw an image using Graphics.DrawImage and draw it at a bigger size than the original image, it ends up being a bit too small. You can see this in the following picture: The green lines shouldn't be visible and are not part of the image. Rather they get drawn behind the image and the image should cover them. How can I draw an image with the exact right size? EDIT : I draw the green part with the same rectangle I pass into the DrawImage call, with the exact dimensions of how big the

Graphics.DrawString vs TextRenderer.DrawText?Which can Deliver Better Quality

六月ゝ 毕业季﹏ 提交于 2019-12-17 06:38:25
问题 TextRenderer is based on GDI and Graphics.DrawString is based on GDI+.Which of these functions can deliver better quality text while drawing text on an image. 回答1: Just my 2 cents: I always use Graphics.DrawString, except when I need to do custom painting for my (Windows Forms) controls. For example in a listbox that has OwnerDraw set, if I attach a DrawItem event handler that fully paints items, including item text. Or in a custom control I have to paint myself. In an application that uses

How to find the actual printable area? (PrintDocument)

不打扰是莪最后的温柔 提交于 2019-12-17 06:24:09
问题 Why is finding out this magic Rectangle so difficult? In the OnPrintPage event I have PrintPageEventArgs and I am trying to draw using the Graphics within the bounds of the maximum printable area. I have tried using PageBounds, PrintableArea, Graphics.VisibleClipBounds, etc. All fail to consistently get the drawing area, especially when switching from Landscape to Portrait layout. PrintableArea does not seem to ever change when you switch from Landscape to Portrait. I have also noticed that

How can I treat the circle as a control after drawing it? - Moving and selecting shapes

自古美人都是妖i 提交于 2019-12-17 04:34:08
问题 Actually, after clicking on each circle i want its color to be changed, for instance, i want it to turn into red,Overall, i wanna treat it as control. i know how to draw the circles that represent the nodes of the graph when i Double click on the picturebox. i'm using the following code: public Form1() { InitializeComponent(); pictureBox1.Paint += new PaintEventHandler(pic_Paint); } public Point positionCursor { get; set; } private List<Point> points = new List<Point>(); public int

How to make two transparent layer with c#?

落爺英雄遲暮 提交于 2019-12-17 03:44:28
问题 There are three consecutive layers, picturebox1(.jpg) -> label1 -> picturebox2(.png transparent) what i want is to make the label1 and pictrurebox2 transparent to the picturebox1 so that label1 can be see through the picturebox2 but its not working.. public Form1() { InitializeComponent(); label1.Parent = pictureBox1; label1.BackColor = Color.Transparent; pictureBox2.Parent = pictureBox1; pictureBox2.BackColor = Color.Transparent; picturebox2.BringToFront(); } so please help me 回答1: If you

Double Buffering when not drawing in OnPaint(): why doesn't it work?

拥有回忆 提交于 2019-12-17 03:18:42
问题 I'm working on a simple vector drawing app in C#/.Net. The drawing is done in a panel, but I'm not using the OnPaint() event for all of it - in fact the OnPaint() even just calls another method which actually draws everything in the document. I tried to add double buffering, but when I set DoubleBuffered to true, the flicker issue is even worse. Why is this? If I want to double buffer the control, do I absolutely have to do all my drawing in the OnPaint() event, with the supplied Graphics