FAQ Database Discussion Community


C++ GDI+ bitmap manipulation needs speed up on byte operations

c++,performance,bitmap,gdi+
I'm using GDI+ in C++ to manipulate some Bitmap images, changing the colour and resizing the images. My code is very slow at one particular point and I was looking for some potential ways to speed up the line that's been highlighted in the VS2013 Profiler for (UINT y =...

How to release an object created from GdipCreateBitmapFromHBITMAP?

c,winapi,bitmap,gdi+
I'm writing a C application and in my code I'm calling the constructor GdipCreateBitmapFromHBITMAP. I know the constructor should not be called from C, but I used a "hack" from here "How can I take a screenshot and save it as JPEG on Windows?" I'm not sure how to release...

C# Generic GDI+ Error when using Image.Save()

c#,windows,windows-xp,gdi+,tiff
I am a relative novice with imaging in C#. This is my first question on this board after a very long time of being a member. I hope it can help me get through this tricky scenario. I need to read the contents (frames) of a Multi Page TIFF, saving...

Converting From Brush/Pens To Color

.net,vb.net,gdi+,brush,pen
I am making a paint program and the color of the PictureBox Graphics supports Brushes in FillShape and Pens in DrawShape. If you have any solution please tell me how to convert Brush/Pens to Color? So I can also use ColorDialog for custom colors....

GDI+ curve “overflowing”

c#,graphics,graph,gdi+
I'm currently using GDI+ to draw a line graph, and using Graphics.DrawCurve to smooth out the line. The problem is that the curve doesn't always match the points I feed it, and that makes the curve grow out of the graph frame in some points, as seen below(red is Graphics.DrawLines,...

GDI+: Grayscale PNG loaded as PixelFormat32bppARGB

c++,windows,gdi+
I am trying to load a grayscale PNG file using GDI+ on Windows 7/64bits Pro. However if I use the value returned from Image::GetPixelFormat(), it tells me that the pixelFormat is PixelFormat32bppARGB. If I convert this PNG to JPG and/or TIFF it now tells me that the pixelFormat is now...

What are the consequences of not calling GdiplusShutdown before exiting an application?

c++,mfc,gdi+
I'm currently working on a legacy MFC application and I noticed that there was a missing call to GdiplusShutdown() before exiting the application. The documentation clearly states that each GdiplusStartup call must be paired by a call to GdiplusShutdown(). What happens if this function is not called ? Object leak,...

GDI+: How to replace black pixels with red pixels?

c++,bitmap,gdi+
I have a black and white image, a would like to replace the black pixels with red pixels. I've tried Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(filename); Gdiplus::ImageAttributes ia; Gdiplus::ColorMatrix m = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,...

gdi+ PrivateFontCollection AddFontFile always returns status with “InvalidParameter”

c++,fonts,gdi+,win32gui,typeface
every one, I'm using GDI+ to rendering text with my own typeface, but I always get a error status InvalidParameter when using member function AddFontFile(WCHAR*) of PrivateFontCollection to load my font file, here is my code: PrivateFontCollection m_font_collection; ... // initialize window GdiplusStartup(&gdi_token, &gdi_startup_input, NULL); // here the result always...

Custom draw dropdown panel outside Control bounds

c#,winforms,graphics,gdi+,gdi
I seem to have picked up an "unclear what I'm asking" vote. I want to custom draw a combo box style control. The pop open section needs to draw outside the bounds of the control itself. I cannot use combo box - think something similar to the gallery control in...

Center image on another Image C#

c#,winforms,gdi+,autoresize
Hi I am fairly new to C# GDI+ graphics, I want to draw an image over another, which should be centered horizontally and vertically in a fixed height and width container on an image, I tried to do this with horizontal centering and the output is weird.. I am sharing...

Images (PNG) don't show up in final exe of c++ Win32 project

c++,gdi+
To begin with, a small sample of my code: // Includes and namespaces #include <windows.h> #include <windowsx.h> #include <stdlib.h> #include <string> #include <tchar.h> #include <objidl.h> #include <gdiplus.h> using namespace Gdiplus; using namespace std; #pragma comment (lib,"Gdiplus.lib") /*---------------------------------------------------------------------------------------------*/ // Forward declarations static TCHAR szWindowClassIntro[] = _T("codbo2_trainer_intro"); static TCHAR szTitle[] =...

How to draw string in GDI+ Graphics.DrawString that honors the underline chars when I use ampersand?

delphi,graphics,gdi+,drawstring,drawtext
I'm using GDI+ to draw a string but it does not act like windows DrawText when it comes to honoring the & in front of the a char. It just draws & and not underlines next char. Maybe there is an option to turn it on/off? Please help.

C# GDI+ generic error / external exception after saving multiple images

c#,image-processing,gdi+,tiff
I have a little console application in C# that takes a pair of pictures from a folder (containing a few hundred images) in .jpg-format, merges them to one picture and stores the result as .tif in another folder. This process is repeated for all pictures in the source folder. It...

Dynamic font size to draw string inside a rectangle

c#,.net,winforms,gdi+
I am drawing a rectangle in the paint method of a control. There is a zoom factor to consider, e.g. each positive MouseWheel event causes the control to repaint and then the rectangle gets bigger. Now I am drawing a string inside this rectangle, but I couldn't figure out how...

GDI+, Remove white space from Graphics DrawString()

c#,gdi+
I have a problem with C# GDI+ draw string functions -- I can not get the exact size of my drawn string -- without internal leading and external leading, just the em height. The font/string Measuring APIs provided by Microsoft seems to always output a bounding box that is a...

Draw checkbox tick according to the box size?

.net,vb.net,winforms,user-controls,gdi+
Introduction I'm writting a simple checkbox user-control that will draw a background and a tick in a custom color. To draw the tick, I do this: ''' <summary> ''' Draws the checkbox tick. ''' </summary> ''' <param name="g">The drawing surface.</param> ''' <param name="rect">The box rectangle.</param> ''' <param name="checkState">The checkbox state.</param>...

DrawParentBackground / DrawThemeParentBackground on a top level form

c#,winforms,gdi+,gdi
Consider the following example. This was done by setting the TransparencyKey property: public Form() { this.InitializeComponent(); this.BackColor = Color.Fuscia; this.TransparencyKey = this.BackColor; } What I actually want to be able to do is similar to the behavior of the DrawThemeParentBackground function (conveniently wrapped up in .NET as DrawParentBackground), however this...

Resize PNG image without losing color data from fully transparent pixels

c#,png,gdi+,alpha
I've been trying to figure out a way to resize a PNG image without losing color data from pixels that are completely transparent. Here is the code that I'm using to achieve this: //sourceImage is also a bitmap read in earlier using (var scaledBitmap = new Bitmap(desiredWidth, desiredHeight, PixelFormat.Format32bppArgb)){ using...

Substitute the GetHashCode() Method of System.Drawing.Point

c#,performance,gdi+,gethashcode
System.Drawing.Point has a really, really bad GetHashCode method if you intend to use it to describes 'pixels' in a Image/Bitmap: it is just XOR between the X and Y coordinates. So for a image with, say, 2000x2000 size, it has an absurd number of colisions, since only the numbers in...

Generic error in GDI+

c#,gdi+,bmp
I am saving images from camera in a loop but some times it gives generic error in gdi+ in some system while i use i7 4gb ram and it dosent come when i use i3 4gnb ram system for (int i = 1; i <= frameno; i++) { Bitmap bm...

GraphicsPath.IsVisible() doesn't match up with actual path?

c#,.net,gdi+,region,hittest
I'm experiencing a discrepancy between a GraphicsPath drawn in World coordinates on a UserControl and the results of GraphicsPath.IsVisible() to Hit Test the shape with the mouse. I performed a little test that made a map of where IsVisible() returned true, relative to the GraphicsPath shape that was drawn. The...

What is causing Calibri to lose ClearType between 9 and 14 pt?

c#,fonts,gdi+,opentype,cleartype
What exactly is it that makes GDI+ switch to binary aliasing when using default Microsoft Office font Calibri between 9pt and 14pt with ClearTypeGridFit specified? It's somewhat disconcerting. How many other fonts are also affected by whatever is behind this, and at what sizes? Is there a workaround? (Excluding GDI,...

Increase brightness of specific color in image?

c#,.net,vb.net,image-processing,gdi+
Having an image like this (original size increased by 100%): Under C# or else Vb.Net, I wonder if I could use a color matrix or other workaround to increase the brightness/luminosity only to the white/greyed color of that image keeping the black background color untouched? In other words, I would...

Clipping a graphic in memory before drawing on form

c#,drawing,gdi+,widescreen
I'm trying to use the following code to copy a portion of the screen to a new location on my Windows form. private void Form1_Paint(object sender, PaintEventArgs e) { var srcPoint = new Point(0,0); var dstPoint = new Point(Screen.PrimaryScreen.Bounds.Width/2, Screen.PrimaryScreen.Bounds.Height/2); var copySize = new Size(100, 100); e.Graphics.CopyFromScreen(srcPoint, dstPoint, copySize, CopyPixelOperation.SourceCopy);...

Graphics.DrawPath and LinearGradientBrush issue

c#,winforms,gdi+,gdi,lineargradientbrush
In relation to this question that I asked a few weeks ago now LinearGradientBrush does not render correctly Consider the following code: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle rect = new Rectangle(100, 100, 200, 100); using(LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Red, Color.Blue, 90)) { using(Pen pen = new...

Making unsafe code safe in C#

c#,.net,pointers,gdi+,unsafe
I was recently reading through an article on image processing in C# There is a bit of code in there that I don't really like because it's unsafe, and I would like to know if it can be made safe: public static bool Invert(Bitmap b) { // GDI+ still lies...

GDI Overall Clipping Bounds

c#,winforms,graphics,gdi+,gdi
Does GDI have any method of setting an overall clipping area, in the same way the GDI+ Graphics object does? Specifically: Graphics.DrawString uses GDI+ which includes the clipping bounds system. TextRenderer.DrawText uses GDI which does not. My new scrollbar system automatically resizes the Graphics draw area as needed. While tidying...