gdi+

How to Create a Gdiplus::Bitmap from an HBITMAP, retaining the alpha channel information?

久未见 提交于 2019-12-18 06:08:44
问题 When I create a new Gdiplus::Bitmap using the Bitmap::FromHBITMAP function, the resulting Bitmap is opaque - none of the partial transparency from the original HBITMAP is preserved. Is there a way to create a Gdiplus::Bitmap from an HBITMAP which brings across the alpha channel data? 回答1: I think working code is more useful than instructions, so: #include <GdiPlus.h> #include <memory> Gdiplus::Status HBitmapToBitmap( HBITMAP source, Gdiplus::PixelFormat pixel_format, Gdiplus::Bitmap** result

Inverting image returns a black image

↘锁芯ラ 提交于 2019-12-17 21:08:33
问题 I want to invert an Image object. Currently my code looks like this: private Image Invert(Image img) { var bmpPicture = new Bitmap(img.Width, img.Height); var iaPicture = new ImageAttributes(); var cmPicture = new ColorMatrix { Matrix00 = -1, Matrix11 = -1, Matrix22 = -1 }; iaPicture.SetColorMatrix(cmPicture); var gfxPicture = Graphics.FromImage(img); var rctPicture = new Rectangle(0, 0, img.Width, img.Height); gfxPicture.DrawImage(img, rctPicture, 0, 0, img.Width, img.Height, GraphicsUnit

Editing 8bpp indexed Bitmaps

Deadly 提交于 2019-12-17 20:59:07
问题 i'm trying to edit the pixels of a 8bpp. Since this PixelFormat is indexed i'm aware that it uses a Color Table to map the pixel values. Even though I can edit the bitmap by converting it to 24bpp, 8bpp editing is much faster (13ms vs 3ms). But, changing each value when accessing the 8bpp bitmap results in some random rgb colors even though the PixelFormat remains 8bpp. I'm currently developing in c# and the algorithm is as follows: (C#) 1- Load original Bitmap at 8bpp 2- Create Empty temp

Region.IsVisible(PointF) has very slow performance for large floating point values

拥有回忆 提交于 2019-12-17 20:48:56
问题 I have run into a strange performance issue, and it would be great with an explanation to the behavior I'm experiencing. I'm using System.Drawing.Region.IsVisible(PointF) to determine if a point is inside a polygon. This usually works very well, but yesterday I noticed that the performance of the IsVisible method becomes very slow if the polygon is complex and it consists of large x- and y values. Below is some code to reproduce the issue (and an image that shows the shape of the polygon),

GDI+ generic error saving bitmap created from memory using LockBits

无人久伴 提交于 2019-12-17 20:21:19
问题 The GDI+ generic error when saving a bitmap is obviously a common problem according to my research here on SO and the web. Given following simplified snippet: byte[] bytes = new byte[2048 * 2048 * 2]; for (int i = 0; i < bytes.Length; i++) { // set random or constant pixel data, whatever you want } Bitmap bmp = new Bitmap(2048, 2048, PixelFormat.Format16bppGrayScale); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 2048, 2048), ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime

How to delete the file of a PrivateFontCollection.AddFontFile?

家住魔仙堡 提交于 2019-12-17 19:28:25
问题 We create a large count of fonts for a short use. The fonts are embedded in documents. I want delete the font files if not use anymore. How can we do this? The follow simplified code does not work: PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(fontFile); FontFamily family = pfc.Families[0]; Console.WriteLine(family.GetName(0)); family.Dispose(); pfc.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); File.Delete(fontFile); The delete of the file is failing

GDI+ MeasureString() is incorrectly trimming text

China☆狼群 提交于 2019-12-17 17:09:28
问题 I am trying to complete a code that can layout text on the screen. The following C# code placed in the Paint event handler of an otherwise empty Windows Form is an example: string[] s = new string[] { "Sample text ", "to test", " this layout ", "algorithm" }; PointF[] pts = new PointF[s.Length]; PointF start = new PointF(10, 10); StringFormat f = new StringFormat(StringFormat.GenericTypographic); float x = start.X; float y = start.Y; for (int i = 0; i < pts.Length; i++) { pts[i] = new PointF

Flip the GraphicsPath that draws the text/string

纵然是瞬间 提交于 2019-12-17 16:52:42
问题 I have this method in my Text Class and I can't seem to flip the whole text. I am using a Matrix to transform the GraphicsPath which is used to draw the string. Here's the code since I used @Jimi's answer: public LayerClass DrawString(LayerClass.Type _text, string text, RectangleF rect, Font _fontStyle, Brush brush, float angle, PaintEventArgs e) { using (StringFormat string_format = new StringFormat()) { SizeF stringSize = e.Graphics.MeasureString(text, _fontStyle); rect.Location = new

When drawing an image: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI

本小妞迷上赌 提交于 2019-12-17 16:27:59
问题 I've got a global Graphics object created from a Panel. At regular intervals an image is picked up from the disk and drawn into the panel using Graphics.DrawImage(). It works fine for a few iterations and then I'm getting the following helpful exception: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y) at System.Drawing.Graphics

Windows Aero: What color to paint to make “glass” appear?

一世执手 提交于 2019-12-17 15:28:34
问题 What color must i paint in the client area in order to make glass appear? i've extended the frame of my form into the client area using: DwmExtendFrameIntoClientArea(self.Handle, margins); i cannot find any official documentation from Microsoft on what color and/or alpha the DWM will look for to replace with glass. The documentation on DwmExtendFrameInClientArea doesn't even mention that a custom color is required. There's only hearsay and myth that a special color is even required. The