gdi+

LinearGradientBrush Artifact Workaround?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 03:29:21
The LinearGradientBrush in .net (or even in GDI+ as a whole?) seems to have a severe bug: Sometimes, it introduces artifacts. (See here or here - essentially, the first line of a linear gradient is drawn in the endcolor, i.e. a gradient from White to Black will start with a Black line and then with the proper White to Black gradient) I wonder if anyone found a working workaround for this? This is a really annoying bug :-( Here is a picture of the Artifacts, note that there are 2 LinearGradientBrushes: alt text http://img142.imageshack.us/img142/7711/gradientartifactmm6.jpg I have noticed this

Font size discrepancy in .NET GDI+?

我与影子孤独终老i 提交于 2019-12-04 03:27:31
I am wracking my brains in trying to understand the discrepancy between the font sizes users select or specify (for example, using a FontDialog ) and the em-size reported by the Font class in .NET. For example: using (FontDialog dlg = new FontDialog()) { if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine("Selected font size: " + dlg.Font.SizeInPoints.ToString("0.##")); } } Using the above code, you will get some confusing results: Selecting 11 in the dialog produces 11.25 Selecting 12 in the dialog produces 12 Selecting 14 in the dialog produces 14.25 Selecting 16 in the dialog

Render Translucent/Transparent Overlay

馋奶兔 提交于 2019-12-04 03:25:52
I need a fast way to draw an overlay on a screen with transparency support. I've done a lot of searching and found one potential solution (which has its own problems) and another solution that does not fit my requirements; specifically transparency support. I'll start with the latter and then touch on the former. Solution 1 Using a borderless form with a TransparencyKey, this is one of the most recommended solutions I've found and the least helpful. This solution works by having a new Form, have it borderless, set the background to something like Colour.White and set the TransparencyKey to the

When do you dispose GDI+ resources?

隐身守侯 提交于 2019-12-04 02:54:38
Many GDI+ classes implement IDisposable, but I'm not sure when I should call Dispose. It's clear for instances I create with new or static methods like Graphics.CreateGraphics . But what about objects that are returned by property getters? I often write code like this: var oldRgn = g.Clip; using (var rectRegion = new Region(rectangle)) { g.Clip = rectRegion; // draw something } g.Clip = oldRgn; Am I supposed to dispose oldRgn after that? My memory profiler tells me there are undisposed instances if I don't. And looking at the implementation in reflector at least confirms that the getter

BinaryFormatter.Serialize( Image ) - ExternalException - A generic error occurred in GDI+

别来无恙 提交于 2019-12-04 01:44:59
问题 When I try to Serialize some images using the BinaryFormatter, I'll get a ExternalException - A generic error occurred in GDI+." After scratching my head for awhile, I decided to create a simple test project to narrow down the problem: static void Main(string[] args) { string file = @"C:\temp\delme.jpg"; //Image i = new Bitmap(file); //using(FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) byte[] data = File.ReadAllBytes(file); using(MemoryStream originalms = new

How do I load and save an image from an SQL Server database using GDI+ and C++?

风流意气都作罢 提交于 2019-12-04 01:34:56
问题 I need specifically to load a JPG image that was saved as a blob. GDI+ makes it very easy to retrieve images from files but not from databases... 回答1: Take a look at Image::Image(IStream *, BOOL). This takes a pointer to a COM object implementing the IStream interface. You can get one of these by allocating some global memory with GlobalAlloc and then calling CreateStreamOnHGlobal on the returned handle. It'll look something like this: shared_ptr<Image> CreateImage(BYTE *blob, size_t blobSize

Non-Affine image transformations in .NET

笑着哭i 提交于 2019-12-04 01:13:13
问题 Are there any classes, methods in the .NET library, or any algorithms in general, to perform non-affine transformations? (i.e. transformations that involve more than just rotation, scale, translation and shear) e.g.: (source: last100.com) Is there another term for non-affine transformations? 回答1: All of the example images you posted can be done with a Quadrilateral Distortion. Though I cant say for certain that a quad distort will cover ALL non affine transforms. Heres a link to a not so good

A generic error occurred in GDI+

断了今生、忘了曾经 提交于 2019-12-03 23:25:45
问题 I loaded an image into a Picture Box using: picturebox1.Image = Image.FromFile() and I save it by using: Bitmap bm = new Bitmap(pictureBox1.Image); bm.Save(FileName, ImageFormat.Bmp); It works perfectly fine when creating a new file, but when I try to replace the existing image, I get thrown the following runtime error: A generic error occurred in GDI+ So what can I do to solve this problem?? 回答1: That because the image file is used by your picturebox1.Image , try to save it to different file

Drawing a partially transparent GDI+ Bitmap to a borderless window using UpdateLayeredWindow

青春壹個敷衍的年華 提交于 2019-12-03 23:07:14
I'm trying to create a non-rectangular window with semi-transparent pixels. The image does not come from a PNG but is drawn on-the-fly using GDI+ calls. I create the window as follows: WNDCLASSEX wc = WNDCLASSEX(); wc.cbSize = sizeof(wc); HINSTANCE instance = GetModuleHandle(nullptr); std::wstring classname(L"gditest ui window class"); if (!GetClassInfoEx(instance, classname.c_str(), &wc)) { //wc.cbSize; //wc.style = CS_DROPSHADOW; wc.lpfnWndProc = process_messages; //wc.cbClsExtra; //wc.cbWndExtra; wc.hInstance = instance; wc.hIcon; wc.hCursor = LoadCursor(0, IDC_ARROW); //wc.hbrBackground; /

Should I create new Pens/Brushes per Paint request or keep them throughout the application lifecycle?

混江龙づ霸主 提交于 2019-12-03 23:04:39
I have an application that does a lot of drawing, let's pretend it's a Viso-like application. It has objects that have multiple sub-objects that are drawn, things can be connected, resized etc. Currently when I call paint on a particular sub-object or object, I do the following: using(var pen = new Pen(this.ForeColor)) { // Paint for this object. } I've read conflicting answers that this should be done for an application that is constantly drawing the same thing (maybe just resized, moved etc). Should I store the Pen/Brush with the object and then dispose them all when the application is