gdi+

Change image color with transparent background

好久不见. 提交于 2019-12-05 14:05:56
I need to load an image with green circle over a transparent background into a bitmap image using c# (System.Drawings). That's the easy part. However I need to change the color of the circle before adding it to the bigger image, without affecting the transparency of the surrounding. In my case I need to change the circle color to yellow and add it as a sun. I can't use fixed yellow circle image because the desired color is dynamic. So in the code below, how can I change the color of the image before adding it to the bitmap? Image i = Image.FromFile(greenCircleFile); Bitmap b = new Bitmap(500,

Bitmap Graphics vs WinForm Control Graphics

时间秒杀一切 提交于 2019-12-05 13:44:52
I'm just using a .NET port of Pdfium named PdfiumViewer . It just works very well once rendered in the WinForm controls but when I try to render it on a Bitmap to show in the WPF windows (or even saving to disk) the rendered text has problem. var pdfDoc = PdfiumViewer.PdfDocument.Load(FileName); int width = (int)(this.ActualWidth - 30) / 2; int height = (int)this.ActualHeight - 30; var bitmap = new System.Drawing.Bitmap(width, height); var g = System.Drawing.Graphics.FromImage(bitmap); g.FillRegion(System.Drawing.Brushes.White, new System.Drawing.Region( new System.Drawing.RectangleF(0, 0,

Measure wrapped string

血红的双手。 提交于 2019-12-05 13:13:19
I'm trying to create a Control that basically allows me to draw different strings underneath one another. However, the strings' width may not be larger than the control's. In order to solve that problem, I was thinking of passing a RectangleF object to the Graphics.DrawString method. That would wrap strings which are wider than the passed rectangle's width. Although this does solve the problem of not being able to see the whole string if it's too big, there is another problem. If I were to try something like this Graphics g = e.Graphics; // Paint event g.DrawString(someText, someFont,

Check If Image Is Colored Or Not

时光毁灭记忆、已成空白 提交于 2019-12-05 13:04:28
I'm trying to figure out whether an image is colored or not. On this StackOverflow question, there's a reply that says that I should check the PixelFormat enum of the Image . Unfortunately, the reply isn't very clear to me. Is it safe to check whether the image.PixelFormat is different from PixelFormat.Format16bppGrayScale to consider that it is a colored image? What about the other values of the enumeration? The MSDN documentation isn't very clear... You can improve this by avoiding Color.FromArgb, and iterating over bytes instead of ints, but I thought this would be more readable for you,

Saving a modified image to the original file using GDI+

我与影子孤独终老i 提交于 2019-12-05 12:54:41
I was loading a Bitmap Image from a File. When I tried to save the Image to another file I got the following error "A generic error occurred in GDI+". I believe this is because the file is locked by the image object. Ok so tried calling the Image.Clone function. This still locks the file. hmm. Next I try loading a Bitmap Image from a FileStream and load the image into memory so GDI+ doesn't lock the file. This works great except I need to generate thumbnails using Image.GetThumbnailImage method it throws an out of memory exception. Apparently I need to keep the stream open to stop this

Obtaining kerning information

☆樱花仙子☆ 提交于 2019-12-05 12:24:07
How can I obtain kerning information for GDI to then use in GetKerningPairs ? The documentation states that The number of pairs in the lpkrnpair array. If the font has more than nNumPairs kerning pairs, the function returns an error. However, I do not know how many pairs to pass in, and I don't see a way to query for it. EDIT #2 Here is my fill application that I have also tried, this is always producing 0 for any font for the number of pairs. GetLastError will always return 0 also. #include <windows.h> #include <Gdiplus.h> #include <iostream> using namespace std; using namespace Gdiplus; int

Why is my c# paint method running out of memory?

只谈情不闲聊 提交于 2019-12-05 12:18:36
I'm new to c#, and trying to learn by writing some simple apps to get familiar with the syntax and .NET library. The most recent miniproject I took on is a polar clock like the one found here . One of the problems I noticed early on was that the app would constantly "flicker", which really took away from the presentation, so I read online about how to implement a double buffer, which eliminated this problem, but may or may not have something to do with the problem. Here is my onPaint method; it is called every 33ms (~30 FPS) by a timer control. Most of the rest of the app is simply handlers

Static controls slightly flicker when main window is resized

痴心易碎 提交于 2019-12-05 10:57:34
INTRODUCTION AND RELEVANT INFORMATION: I have a complex painting to implement in my main window’s WM_PAINT handler. I have submitted a picture bellow to illustrate it: Main window has static controls, instead of buttons, which have style SS_NOTIFY . When user clicks on them, certain actions occur in program. The following picture shows where static controls in the main window are: Map on the orange panel is an EMF file ,top left and right logos are PNG files, and other pictures are bitmaps. In order to implement this task, I have decided to draw the entire picture in WM_PAINT , and to put

how to draw constantly changing graphics

自闭症网瘾萝莉.ら 提交于 2019-12-05 05:42:05
问题 Have not done this before (except in java, look how Steve McLeod fixed it), so obviously I suck at it. Here 64 pixels around current mouse position get drawn little bigger on a form. Problem is, that it's 'kind of' to slow, and I have no idea where to start fixing. Besides that, I made a timer thread, that constantly calls update graphics when it's finished and a little fps like text, to show really how fast things are drawn. Image example: (Image is from letter 'a' in "IntelliTrace" in

C# Setting FontDialog to only display TrueType fonts

假如想象 提交于 2019-12-05 04:50:35
This question has been asked in practically every forum, including here but there are no acceptable answers anywhere that I can find. I'm beginning to think that there is actually no solution and I just have to wrap my code in a try/catch block and apologise to the user and ask them to pick another font. I want to show a FontDialog so that a user can change the fonts on a Chart , however if the user selects a non-TrueType font, then an exception is thrown. GDI+ can only handle TrueType fonts. How can I filter the fonts from the FontDialog which cannot be used with GDI+? The FontDialog class