gdi+

A strange Problem about gdi+ bitmap!

I am using the following code to get a Bitmap point, (width = 800, height = 600); Bitmap* m_BitmapCanvasCore = new Bitmap(width, height, PixelFormat32bppARGB); but the m_BitmapCanvasCore always is NULL... Is there any thing wrong about gdi+? Or any namespace polution I need to avoid? Why? ...

Can Any one offer me a sample in gdi+ to draw an image on canvas?

I need to draw an image with a certain angle on a canvas, it need to rotate angle N , and its center is on x, y Matrix myPathMatrix; myPathMatrix.Translate(x, y, MatrixOrderAppend); myPathMatrix.Rotate(angle, MatrixOrderAppend); canvas->SetTransform(&myPathMatrix); Draw(canvas);// draw the image myPathMatrix.Rotate(-an...

How to avoid Alias when rotate the image in gdi+?

I have a problem on roating an Image on a canvas in gdi+, I am using the following code, however I find there are alias on the edge. myPathMatrix.Rotate(GetDCAngle(), MatrixOrderAppend); myPathMatrix.Translate( GetDCX(), GetDCY(), MatrixOrderAppend); canvas->SetTransform(&myPathMatrix); canvas->Draw(XXX); I used the following code t...

GDI+: Alternatives to DrawReversible for visual selection indicators?

I've searched around for an alternative way of drawing selection indicators for visual objects (like selected edges, lines etc.) without the use of ControlPaint.DrawReversibleFrame and related XOR methods. The reasons are unwanted XOR-ing "artifacts", reversibility not applying to bitmaps, no control of the actual visual look and slownes...

How to disable subsampling with .NET / GDI+ ?

I am trying to save a JPEG image using the Bitmap class. I noticed that sharp edges were always blury regardless of the quality level that I specify. I figured out that it is due to subsampling of one or more of the channels. How do I disable subsampling when saving the image? I am currently using this code: EncoderParameters parameter...

How to get Words length and height, when drawing the images on a canvas in GDI+

I draw a string on a canvas, using GDI+ in C++. Is there any API to get the out layer (width, height ) of a string in a certain font? Thanks very much! Many thanks to Windows programmer's solution. I wrote the following code. Bitmap bitmap(1000,1000); Graphics graphics(&bitmap); RectF rec; RectF useless; graphics.MeasureString(m_sW...

How to erase the content on a graphics in GDI+?

I am using gdi+, in c++. Bitmap canvasImg = new Bitmap(400, 300, PixelFormat32bppARGB); Graphics canvas = new Graphics(&canvasImg ); canvas.DrawImage(XXXX); There are two problems. 1. I find the canvasImg is black. How can I change the color to white? I mean I want an white canvas. 2. If I have drawn some thing on the canvas, How c...

What is the fastest way to draw an Image on another image?

I have 3 Bitmap point . Bitmap* totalCanvas = new Bitmap(400, 300, PixelFormat32bppARGB); // final canvas Bitmap* bottomLayer = new Bitmap(400, 300,PixelFormat32bppARGB); // background Bitmap* topLayer = new Bitmap(XXX); // always changed. I will draw complex background on bottomLayer. I don't want to redraw complex background on to...

How important is disposing a Font, really?

I'm aware that the best practice is to call Dispose on any object that implements IDisposable, especially objects that wrap finite resources like file handles, sockets, GDI handles, etc. But I'm running into a case where I have an object that has a Font, and I would have to plumb IDisposable through several layers of objects, and review...

(.NET/C#/winforms) Artifacting when drawing on a Form with Graphics

My objective is to move visual elements drawn using methods of a Graphics object across a Form with no flicker or artifacting (in .NET 3.5). I can successfully achieve flickerless movement by either using automatic double buffering (setting the Form's DoubleBuffered property to true) or implementing a back-buffer myself. I am however s...

Dashed rectangles appear solid when expanding Winform window.

I'm experiencing an issue with GDI+ while custom painting dashed rectangles. The vertical portion of dashed rectangles appear as solid, continuous lines when the window size is increased or when scrolling up/down. Moving the mouse faster results in fewer and fewer solid sections. Curiously the horizontal lines do not exhibit this be...

Does someone have an optimized function to premultiply bitmap by alpha ?

GDIPlus blend functions use premultiplied rgb channel by alpha bitmaps for efficiency. However premultiplying by alpha is a very costly since you have to treat each pixel one by one. It seem that it would be a good candidate for SSE assembly. Is there someone here that would want to share its implementation? I know that this is hard wor...

Draw a single pixel on Windows Forms

I'm stuck trying to turn on a single pixel on a Windows Form. graphics.DrawLine(Pens.Black, 50, 50, 51, 50); // draws two pixels graphics.DrawLine(Pens.Black, 50, 50, 50, 50); // draws no pixels The API really should have a method to set the color of one pixel, but I don't see one. I am using C#. ...

c# Non-Linear gradient brushes?

Is there a method I can use to generate non-linear Gradient brushes in c#? To clarify: Im not looking for a gradient that can be applied to a non-linear path. Rather, I am looking for a gradient between 2 colours that fades between the two in a non-linear fashion i.e. the rate of changs is quicker at the start of the gradient and slows ...

Why does Image.FromFile keep a file handle open sometimes?

I am doing a lot of image processing in GDI+ in .NET in an ASP.NET application. I frequently find that Image.FromFile() is keeping a file handle open. Why is this? What is the best way to open an image without the file handle being retained. NB: I'm not doing anything stupid like keeping the Image object lying around - and even if I ...

How can I load an image from a resource using GDI+?

I am trying to load a non-bmp image (png in my case) into a Bitmap/Image instance from a resource in my app. Since the Bitmap constructor only has an overload for a bitmap resource, this is what i've came around: I allocate memory on the global heap, and then copy the resource data into it. Then I create an IStream for that global memor...

Generic GDI+ error with ThreadExceptionDialog in stack trace

We received some hard to reproduce error reports. The users gets the "An error occurred. The application will now exit." message box and then the app exits. In Main() I write the exception to a log file: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.FromHbitmap(IntPtr hbitma...

Setting Palette on ASP.net/GDI+ Generated PNG Image

I just built an application in ASP.net that returns a PNG image. The resulting image is entirely black on a transparent background. Is there a way to index the image to reduce the file size? I can not index the new image as it is created because I am using the graphics object which will not allow it. Thank you very much for the help -...

Using WPF on a DLL to create Images Dynamically (instead of GDI+)

I need to generate an image dynamically, and after I read the tutorial here I realize i can use all the controls and layouts from WPF to generate my rendering, and then save it as a JPG. The idea is to use this instead of GDI+, which is quite primitive. The question is, how to I create a regular dll file that would generate programatic...

Text rendering control in GDI+

I've been struggling for a while with the text rendering in GDI+. We are dynamically generating images of headlines but there seems to be a lot to whish for in the library. I can set the font, font size and a few other things but I cannot control row height or letter spacing. I have built my own class that takes a generated text image,...