gdi+

PrivateFontCollection with gdi+ sometimes uses the wrong FontStyle in WIndows 8 or newer

江枫思渺然 提交于 2019-12-24 03:09:03
问题 If you have a Font which you've created from a PrivateFontCollection and try to draw strings with it using GDI+ it will sometimes use the wrong FontStyle. I've observed this both with Fonts loaded into a PrivateFontCollection from memory and fonts loaded into PrivateFontCollection from files. In my following example I'm loading fonts from file. I have them all in a folder called Fonts. if we would load them like below. private void loadFontsIntoPrivateCollection() { _privateFontCollection =

How do I capture a WinForm window to a bitmap without the caret

南笙酒味 提交于 2019-12-24 01:11:13
问题 I've got window on a WinForm that I want to get the bitmap representation of. For this, I use the following code (where codeEditor is the control I want a bitmap representation of): public Bitmap GetBitmap( ) { IntPtr srcDC = NativeMethods.GetDC( codeEditor.Handle ) ; var bitmap = new Bitmap( codeEditor.Width, codeEditor.Height ) ; Graphics graphics = Graphics.FromImage( bitmap ) ; var deviceContext = graphics.GetHdc( ) ; bool blitted = NativeMethods.BitBlt( deviceContext, 0, 0, bitmap.Width,

Draw manipulated graphic into another graphic

我与影子孤独终老i 提交于 2019-12-24 00:19:26
问题 I want to draw a manipulated graphic into another: // I have two graphics: var gHead = Graphics.FromImage(h); var gBackground = Graphics.FromImage(b); // Transform the first one var matrix = new Matrix(); matrix.Rotate(30); gHead.Transform = matrix; // Write the first in the second gBackground.DrawImage(h, 200, 0, 170, 170); Output is the background img with the head img - but the head img is not rotated. What am I missing? 回答1: The Transform property of a graphics object is exactly that, a

Slight undesired transparency from FillRectangle

北城余情 提交于 2019-12-23 23:56:31
问题 I have a window created with the WS_EX_LAYERED window style. I am currently drawing onto a memory bitmap using GDI+, and using UpdateLayeredWindow to update the graphical content of my layered window. Here's a snippet of my code: void Redraw(HWND hWnd, int width, int height) { static bool floppy = true; floppy = !floppy; HDC hScreenDC = GetDC(HWND_DESKTOP); HDC hMemDC = CreateCompatibleDC(hScreenDC); HBITMAP hBmp = CreateCompatibleBitmap(hScreenDC, width, height); HGDIOBJ hObj = SelectObject

Detect mouse location within ContainerControl C#.NET [duplicate]

做~自己de王妃 提交于 2019-12-23 18:27:35
问题 This question already has answers here : Pass-through mouse events to parent control (3 answers) Closed 6 years ago . I am testing the following code: protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); Rectangle leftRect = new Rectangle(0, 0, 32, this.Height); if (leftRect.Contains(e.Location)) { MessageBox.Show("Hello World"); } } The idea is that when the mouse enters a region 32 pixels wide, to the left of the container control, a message appears (OK, in R/L it

Image.Save exception “A generic error occurred in GDI+.” when saving to MemoryStream

江枫思渺然 提交于 2019-12-23 17:55:44
问题 I have a server-client application, i want to get a Screen Shot from server,but on the line bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); i get this exception : A generic error occurred in GDI+. private Socket ScreenSocket; private MemoryStream ms; public void ConnectScreenShot(IPEndPoint ep) { if (ScreenSocket != null) { ScreenSocket.Dispose(); ScreenSocket = null; } if (ms != null) { ms.Dispose(); ms = null; } ScreenSocket = new Socket(AddressFamily.InterNetwork, SocketType

GDI+ LockBits()/UnLockBits() Exception

偶尔善良 提交于 2019-12-23 12:29:04
问题 My program is written in C# and manipulates with bitmaps on low level. Everything works fine, but sometimes (very rarely, but stable) exception "Generic GDI+ exception" occurs, and it is very hard to reproduce such situations. Exception happens on functions LockBits() and UnLockBits(). It contains error code "-2147467259". On the language of GDI+ it would be method GdipBitmapLockBits and return code 7 or 1. What kind of reasons may cause such situations? Any answers greatly appreciate. 回答1:

Windows DPI setting affects Graphics.DrawString

萝らか妹 提交于 2019-12-23 12:16:12
问题 I have created a new Bitmap object and now want do draw some text to it using GDI+. So I call Graphics.DrawString(...). The problem is that the size of the string depends on Windows 7's DPI settings. Is there any way to make my text drawing independent of the windows settings? PS: The DPI settings seem to affect text only. A rect for example stys the same size when changing the DPI... 回答1: Just found the solution myself: The key is to create the font with the parameter GraphicsUnit.Pixel.

Draw an image with custom transparency in GDI+

你说的曾经没有我的故事 提交于 2019-12-23 11:58:23
问题 I'm drawing lots of images (all of them dimensions=24x24 pixelformat=32BppPArgb) onto a Control using a Drawing.Graphics object and the DrawImage() function. It's possible to zoom out in my application which means that the Graphics object has a Transform Matrix attached to it which controls both zooming and panning. There's no point in drawing these icons when the zoom drops below 50%, but I'd like to make the transition from drawing icons to not drawing icons smoother. I.e., starting at 70%,

CreateGraphics() Method and Paint Event Args

人盡茶涼 提交于 2019-12-23 10:49:30
问题 I have read somewhere that CreateGraphics() will do this steps for us : BeginPaint Drawing EndPaint I have my code like this : private void Form1_Load(object sender, EventArgs e) { grFrom = this.CreateGraphics(); grFrom.FillRectangle(Brushes.Red, this.ClientRectangle); } There is no red rectangle...but, When I copy line below in Form1_paint , every thing runs correctly. grFrom.FillRectangle(Brushes.Red, this.ClientRectangle); So Question is Here: What is the e.Graphics in Form1_paint ?