gdi+

How to get a 32bpp bitmap/image from a GDI Device Context?

瘦欲@ 提交于 2019-12-24 12:27:07
问题 I am using code from this Project http://www.codeproject.com/Articles/9064/Yet-Another-Transparent-Static-Control in order to draw transparent button images from my subclassed Button control onto my CDialogEx. This code is meant for legacy 24bpp GDI functions: BOOL CTransparentStatic2::OnEraseBkgnd(CDC* pDC) { if (m_Bmp.GetSafeHandle() == NULL) { CRect Rect; GetWindowRect(&Rect); CWnd *pParent = GetParent(); ASSERT(pParent); pParent->ScreenToClient(&Rect); //convert our corrdinates to our

Draw shape to alpha channel only

大城市里の小女人 提交于 2019-12-24 09:57:30
问题 I want to draw a shape to the alpha channel only of my image. I can use a colour matrix when drawing an image with Graphics.DrawImage(..), as it has a parameter to pass in the ImageAttributes. Is it possible to do this with the FillEllipse method? Or would I have to draw it to a separate image, then use DrawImage to apply it to my main image? Cheers, Dan. 回答1: You may try something like: Graphics g; g.CompositionMode = CompositingMode.SourceOver; then fill with: Color c = Color.FromArgb(100,

Save bitmap to file has zero in image size field

蓝咒 提交于 2019-12-24 09:35:51
问题 I find when I use the Bitmap.Save method with format ImageFormat.Bmp that the bitmap header info in the file has zero in the biSizeImage field. From what I can see this is ok according to the specs, but unfortunately the crappy embedded device I am forced to work with insists on it being set correctly. So the question is how to go about getting this header info field always set when the bitmap is saved? 回答1: The issue, as you suspect, is that 0 is a perfectly allowable value for the image

How to draw a string on two not adjacent areas

佐手、 提交于 2019-12-24 09:24:18
问题 I can not figure out if there is there any way in GDI32 to draw a string on two not adjacent areas (let's say Rectangles) on a form?. The text should automatically split if the edge of the first rectangle is reached as shown in the example picture. Thanks for your help. 回答1: An example, using two Labels and a TrackBar . The TrackBar determines a string position inside one Label, which reflects on the second Label each time the string is moved . This cascading effect is generated using the

Invalid parameter creating image or bitmap from stream c# XP only

て烟熏妆下的殇ゞ 提交于 2019-12-24 09:06:26
问题 I believe what I am doing is pretty standard. I create some images from embedded resources by calling GetManifestResourceStream on the resource, giving it the path to the .ico file: Bitmap bmp = new Bitmap(Assembly.GetEntryAssembly().GetManifestResourceStream("MeterView.Resources.unlocked.ico")); The bitmap is then used to display an image on my form. This has always worked perfectly on Windows 7 and 8, but now when I try to run the app on an XP SP3 box I get "Invalid Parameter" on the line

WPF with GDI Memory growth

眉间皱痕 提交于 2019-12-24 08:48:43
问题 I'm writing an app in WPF (C#) that plots certain types of fractals. The data sets are 3d points and need to represented as single pixels. The user can click and drag to rotate the plots The amount of points varies but can be quite large (five million plots or more). Currently I am drawing onto a System.Drawing.Bitmap using a Graphics object then setting a WPF Image's Source property to that bitmap. The problem I have is that when i repeatedly redraw the image memory consumption steadily

TextureBrush Out of Memory Exception

大城市里の小女人 提交于 2019-12-24 07:14:17
问题 I'm trying to place a watermark ontop of another image. This is my code: var imgPhoto = Image.FromFile(filePath); var grPhoto = Graphics.FromImage(imgPhoto); var point = new Point(imgPhoto.Width - imgWatermark.Width, imgPhoto.Height - imgWatermark.Height); var brWatermark = new TextureBrush(imgWatermark, new Rectangle(point.X, point.Y, imgWatermark.Width, imgWatermark.Height)); grPhoto.FillRectangle(brWatermark, new Rectangle(point, imgWatermark.Size)); imgPhoto.Save(outputFolder + @"\" +

TextureBrush Out of Memory Exception

笑着哭i 提交于 2019-12-24 07:14:03
问题 I'm trying to place a watermark ontop of another image. This is my code: var imgPhoto = Image.FromFile(filePath); var grPhoto = Graphics.FromImage(imgPhoto); var point = new Point(imgPhoto.Width - imgWatermark.Width, imgPhoto.Height - imgWatermark.Height); var brWatermark = new TextureBrush(imgWatermark, new Rectangle(point.X, point.Y, imgWatermark.Width, imgWatermark.Height)); grPhoto.FillRectangle(brWatermark, new Rectangle(point, imgWatermark.Size)); imgPhoto.Save(outputFolder + @"\" +

How to solve grayish frame issue when Scaling a bitmap using GDI+

我的未来我决定 提交于 2019-12-24 06:25:09
问题 I'm trying to scale down a Bitmap using GDI+ by doing the following: Bitmap newImage = new Bitmap(NewWidth, NewHeight, Im.PixelFormat); Graphics g = Graphics.FromImage(newImage); g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.ScaleTransform(0.1, 0.1); // 10% g.DrawImage(Im, 0, 0, Im.Width, Im.Height); Im

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

情到浓时终转凉″ 提交于 2019-12-24 03:09:14
问题 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 =