system.drawing

How to enable anti-aliasing when rendering WMF to BitMap in C#/WPF/WinForms?

若如初见. 提交于 2019-11-27 18:58:36
问题 Why won't lines etc be anti-aliased when doing this? using (var myGraphics = Graphics.FromImage(bitmap)) { myGraphics.CompositingQuality = CompositingQuality.HighQuality; myGraphics.SmoothingMode = SmoothingMode.HighQuality; myGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; myGraphics.Clear(backgroundColor); myGraphics.EnumerateMetafile(m_metafile, new Point(0, 0), m_metafileDelegate); } The delegate function looks like this: private bool MetafileCallback(EmfPlusRecordType

C# Drawing on Panels

允我心安 提交于 2019-11-27 16:10:20
I'm drawing up a day schedule and representing timeslots with panels, and appointments are yet more panels on top. The user is able to scroll up and down so that the range they can see is shifted earlier or later. When an appointment runs off the end of the visible range, I want there to be a zig-zag indicating that the appointment extends beyond the visible bounds. I've identified the case where this occurs, and I call a private function drawZigZag(Panel p, int direction); to draw it. The day is spread horizontally, and the direction -1 indicates a zigzag on the left and 1 indicates a zigzag

Cannot find Bitmap Class in Class Library (.NET Standard)

家住魔仙堡 提交于 2019-11-27 16:01:27
I want to make a Class Library (.NET Standard) and I'm using System.Drawing, but I get the error: CS0246 C# The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?) I'm using .NET Standard 2.0. Update As of last month (May 2018), Microsoft have a production release (previously it was preview/RC) of System.Drawing.Common , a NuGet package which supersedes both versions of the CoreCompat.System.Drawing package. This should be used going forwards. For now you can use the CoreCompat.System.Drawing nuget package. We've been using it in

Heatmap style gradients in .NET

醉酒当歌 提交于 2019-11-27 15:31:18
I am trying to create a heat map with gradients that look similar to this: This image shows three points and the gradients blend nicely together. Here is what I am currently doing in my drawing function: public void DrawGradient(int x, int y, Graphics g) { using (var ellipsePath = new GraphicsPath()) { var bounds = new Rectangle(x, y, 100, 100); ellipsePath.AddEllipse(bounds); var brush = new PathGradientBrush(ellipsePath); Color[] colors = { Color.FromArgb(64, 0, 0, 255), Color.FromArgb(140, 0, 255, 0), Color.FromArgb(216, 255, 255, 0), Color.FromArgb(255, 255, 0, 0) }; float[]

C# graphics flickering

倖福魔咒の 提交于 2019-11-27 14:01:06
问题 I am working on kind of drawing program but I have a problem with flickering while moving a mouse cursor while drawing a rubberband line. I hope you can help me to remove that flickering of line, here is the code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace GraphicsTest { public partial class Form1 : Form { int xFirst, yFirst; Bitmap bm = new

How to find reason for Generic GDI+ error when saving an image?

蓝咒 提交于 2019-11-27 13:07:41
Having a code that works for ages when loading and storing images, I discovered that I have one single image that breaks this code: const string i1Path = @"c:\my\i1.jpg"; const string i2Path = @"c:\my\i2.jpg"; var i = Image.FromFile(i1Path); i.Save(i2Path, ImageFormat.Jpeg); The exception is: System.Runtime.InteropServices.ExternalException occurred A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at ... As far as I can see, there is nothing

Double buffering with Panel

白昼怎懂夜的黑 提交于 2019-11-27 08:59:31
Double buffering the whole form can be done by setting the value of the "AllPaintingInWmPaint", "UserPaint" and "DoubleBuffer" ControlStyles to "true" ( this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true) ). But this can't happen with a System.Windows.Forms.Panel because the class doesn't allow me to do so. I have found one solution: http://bytes.com/topic/c-sharp/answers/267635-double-buffering-panel-control . I have also tried this: Winforms Double Buffering . It's laggy, even when it's used on a small drawing, I have some custom

PDF Convert to Black And White PNGs

こ雲淡風輕ζ 提交于 2019-11-27 06:29:35
问题 I'm trying to compress PDFs using iTextSharp. There are a lot of pages with color images stored as JPEGs (DCTDECODE)...so I'm converting them to black and white PNGs and replacing them in the document (the PNG is much smaller than a JPG for black and white format) I have the following methods: private static bool TryCompressPdfImages(PdfReader reader) { try { int n = reader.XrefSize; for (int i = 0; i < n; i++) { PdfObject obj = reader.GetPdfObject(i); if (obj == null || !obj.IsStream()) {

How to open a multi-frame TIFF imageformat image in .NET 2.0?

旧城冷巷雨未停 提交于 2019-11-27 05:37:44
问题 Image.FromFile(@"path\filename.tif") or Image.FromStream(memoryStream) both produce image objects with only one frame even though the source is a multi-frame TIFF file. How do you load an image file that retains these frames? The tiffs are saved using the Image.SaveAdd methods frame by frame. They work in other viewers but .NET Image methods will not load these frames, only the first. Does this mean that there is no way to return a multi-frame TIFF from a method where I am passing in a

File.Delete failing when Image.FromFile was called prior it, despite making copy of loaded image and destroying original one

不羁岁月 提交于 2019-11-27 04:53:28
UPDATED I used below solutions (loading Image from stream), but get new problem. img object is absolutely correct Image class instance with all field filled with correct values. But calling img.Save("path/to/new/image.bmp"); on it results in new exception for GDI+ (System.Runtime.InteropServices.ExternalException, in GDI+ interface) - I get error message but is in polish, am not sure how to translate it. Original question I have problem with C# .NET Framework 2.0 Basically I'am trying to achieve: Image img = Image.FromFile("Path/To/Image.bmp"); File.Delete("Path/To/Image.bmp"); // Exception,