gdi+

Bug in Windows /.NET's System.Drawing.Save(Stream, ImageFormat). Corrupt PNG produced

╄→尐↘猪︶ㄣ 提交于 2019-12-12 11:50:16
问题 In some very specific situations, System.Drawing.Save(Stream, Imageformat) creates corrupt PNG images. Is there a way to avoid it, such that: I don't need to use third party libraries, and I don't need to inspect the PNG bytes to know if I need to 'repair' something? Steps to reproduce Create a System.Drawing.BitMap Add content to image such that it results in very specific PNG file size ("When does it occur") Call Save(Stream, Imageformat) -- choose PNG format What is the problem? The

VisualStyleRenderer to bitmap

我怕爱的太早我们不能终老 提交于 2019-12-12 11:01:14
问题 I need to draw a different progress bar through VisualStyleRenderer . Everything works fine if I use Graphics of OnPaint method. But since I want to save it in hard drive, I need to render progressbar in Bitmap object and then save it. Here is example code protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawImage(RenderProgressbarImage(), new Point(5, 5)); //following code works good progressRenderer.SetParameters("PROGRESS", 11, 2); progressRenderer

Graphics.MeasureCharacterRanges giving wrong size calculations

不打扰是莪最后的温柔 提交于 2019-12-12 10:45:01
问题 I'm trying to render some text into a specific part of an image in a Web Forms app. The text will be user entered, so I want to vary the font size to make sure it fits within the bounding box. I have code that was doing this fine on my proof-of-concept implementation, but I'm now trying it against the assets from the designer, which are larger, and I'm getting some odd results. I'm running the size calculation as follows: StringFormat fmt = new StringFormat(); fmt.Alignment = StringAlignment

A generic error occurred in GDI+ exception while uploading an image file

末鹿安然 提交于 2019-12-12 10:22:29
问题 I have already red some answers here on stackoverflow regarding this, but i just can't figure out which part am i disposing too fast: A generic error occurred in GDI+, JPEG Image to MemoryStream Image.Save(..) throws a GDI+ exception because the memory stream is closed The exception is thrown on this line: image.Save(path, imageCodecInfo, encoderParameters); 来源: https://stackoverflow.com/questions/33331370/a-generic-error-occurred-in-gdi-exception-while-uploading-an-image-file

How to draw over second monitor with GDIPLUS

邮差的信 提交于 2019-12-12 10:20:51
问题 I'm want to draw some text and lines over the desktop. I'm using gdiplus.h for print texts with the function DrawString. But its only print text on a primary screen monitor. If has in presentation mode, with 2 monitors I need to print text in a second monitor. #define _WIN32_WINNT 0x500 #include <windows.h> #include <gdiplus.h> using namespace Gdiplus; #pragma comment (lib,"Gdiplus.lib") int main() { HWND desktop = GetDesktopWindow(); HDC hdc = GetWindowDC(desktop); ULONG_PTR m_gdiplusToken;

Outer Glow Effect for Text in a Custom Control

百般思念 提交于 2019-12-12 09:26:52
问题 How to apply Outer Glow on text of Label in c# winforms, and Blur Effect. Using Custom Control As you See, This is Custom Panel and I'm trying to do Glow Effect for the entire text. protected override void OnPaint(PaintEventArgs pe) { //base.OnPaint(pe); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; GraphicsPath GP = new GraphicsPath(); GP.FillMode = FillMode.Alternate; GP.AddString(this.Text, this.Font.FontFamily, 2,

GetDC, ReleaseDC, CS_OWNDC with OpenGL and Gdi+

▼魔方 西西 提交于 2019-12-12 09:01:53
问题 Reading about GetDC/ReleaseDC I should it appears always do the latter, and that CS_OWNDC on a window is considered evil: https://blogs.msdn.microsoft.com/oldnewthing/20060601-06/?p=31003 Looking through my code I see I'm holding onto a DC retrieved from GetDC, which I've sent into wglCreateContextAttribARB. I'm presuming the context is created on that DC so it would be bad manners to subsequently release it from under the driver. Is my assumption correct? At the moment I'm calling ReleaseDC

Clarification about how ColorMatrix transformations work

ⅰ亾dé卋堺 提交于 2019-12-12 08:38:57
问题 I'm doing some work on an image processing app (for fun) and am struggling to fully understand how ColorMatrix transformations work. I get the basics of linear/affine transformations, and can get by just fine by replicating examples online, but I'd like to fully grasp why something works instead of just being satisfied that it works. For example, doing a simple transformation on an image to produce its negative (each color is converted to its respective complimentary) uses the following

When do you dispose GDI+ resources?

北慕城南 提交于 2019-12-12 08:28:03
问题 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

Is GDI+ just a layer on top of GDI, or something new?

那年仲夏 提交于 2019-12-12 07:49:42
问题 When GDI+ came out, I remember all the brouhaha about how it was the "new, faster, better" way to display stuff in Windows. But everytime I looked at it, it seemed to me that it was really just a COM wrapper around GDI. Is that true? Or is GDI+ really an independent graphical library that simply shares some paradigms with GDI? Personally, I'm not sure how it could be independent, but I never saw a definite statement one way or another. 回答1: Many GDI functions are accelerated by the graphics