LinearGradientBrush with TransformationMatrix

Win32 Programming

    Next

  • 1. How to check if Gdiplus::Image and Gdiplus::Graphics are invalid?
    I have this code: std::auto_ptr<Image> img(Image::FromFile(wstr.c_str())); std::auto_ptr<Graphics> gr(Graphics::FromHDC(hPrinterDC)); and I can't check if what I've got are valid pointers. There doesn't seem to be anything resembling "IsValid()" Thanks
  • 2. Drawing an icon so that a particular color is transparent
    In VS 2008 in a project I create an icon as a resource in various image formats using the VS 2008 icon editor. In my code I load the icon with LoadImage and draw it with DrawIconEx on my WM_PAINT's DC. The image draws in the correct place but I want a particular color in the image, white, to be transparent so the image looks better against the background brush of the window, which is a shade of blue. Is there a way of making a particular color of the icon to show as transparent, so the background color of the window shows through it ? I could try to change the particular color in the icon to the background color of the window, but I would like a more generic way of doing this if possible. Thanks !
  • 3. Problem with GDI and Aero
    I use the following api to display a bitmap inside a dialogbox: GetDC LoadBitmap GetObject GetDlgItem GetClientRect ClientToScreen ScreenToClient CreateCompatibleDC SelectObject BitBlt Under Vista with Aero, the bitmap is not displayed. With Aero deactivated or XP, the bitmap is correctly displayed. Even with Aero, there is no api error. I tried various values for BitBlt (SRCCOPY, etc...) without success. Thanks for your help.
  • 4. Can you send uppercase Chars to Terminal Server ?
    Hi, Saw you post. I have code working along the lines that you mentioned. When it sends to Notepad in a non-TS window (normal Windows session), it sends uppercase ok. However when it sends to the TS Window, the characters are always sent as lowercase. Do you have that problem ? Thanks, Rob Crombie robhp AT iprimus DOT com DOT au
  • 5. Image::FromStream: loading IStream with PNG data
    Hello. Loading images from a custom istream using gdi+ functions works for jpeg and tiff image types I tried, but for PNG doesn't. I think the problem is not in PNG data, but in my IStream implementation. I was using a custom istream that implemented IUnknown, ISequentialStream, IStream. when loading the PNG, gdi+ was querying for a IImageBytes (defined in GdiplusImaging.h). why does the png loader section of gdi+ use this, and no other image loader? And more. When I am loading identical PNG data, but from the stream created with SHCreateStreamOnFile everything works fine and no IImageBytes is requested. I Implemented IImageBytes and it works. But this is very odd and isn't acceptable at all. Maybe you have already met and resolved such a situation. What should I do to work without implementing IImageBytes. Thanks for your help and time, Artem Kushnir

LinearGradientBrush with TransformationMatrix

Postby Ronnie Brunn » Sat, 18 Nov 2006 02:50:40 GMT

Hi,

I'm using GDI+ to render SVG Data to EMF+-Metafiles.
Now I ran into a problem with linear gradients. Consider this SVG-file:

----------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
" http://www.**--****.com/ " [
	<!ENTITY ns_svg " http://www.**--****.com/ ">
	<!ENTITY ns_xlink " http://www.**--****.com/ ">
]>
<svg  version="1.1" id="Layer_1" xmlns="&ns_svg;"
xmlns:xlink="&ns_xlink;" width="70.0009766" height="35"
	 viewBox="0 0 70.0009766 35" overflow="visible" enable-background="new
0 0 70.0009766 35" xml:space="preserve">
<linearGradient id="X2" gradientUnits="userSpaceOnUse" x1="479.2060547"
y1="618.0742188" x2="479.2060547" y2="613.9560547"
gradientTransform="matrix(0 -1 17 0 -10437.2431641 496.7466736)">
	<stop  offset="0" style="stop-color:#FCFCFC"/>
	<stop  offset="1" style="stop-color:#FFB376"/>
</linearGradient>
<polygon fill="url(#X2)" points="70.0009766,0 70.0009766,35 0,32 0,3
"/>
</svg>
-----------

The renderer will convert it to something which basically looks like
this:

-----------
{
	HDC tempDC = GetDC(hWnd);
	Gdiplus::Metafile outputfile (L"C:\\gradient.emf",
		tempDC,Gdiplus::EmfTypeEmfPlusOnly);
	ReleaseDC (hWnd,tempDC);
	Gdiplus::Graphics graphics(&outputfile);

	// the polygon
	Gdiplus::PointF aptfPolygon[4];
	aptfPolygon[0].X=70.0009766;
	aptfPolygon[0].Y=0;
	aptfPolygon[1].X=70.0009766;
	aptfPolygon[1].Y=35;
	aptfPolygon[2].X=0;
	aptfPolygon[2].Y=32;
	aptfPolygon[3].X=0;
	aptfPolygon[3].Y=3;
	Gdiplus::GraphicsPath polygon;
	polygon.AddPolygon(aptfPolygon,4);

	// the gradient
	Gdiplus::LinearGradientBrush gradient (
		Gdiplus::PointF(479.2060547,618.0742188),
		Gdiplus::PointF(479.2060547,613.9560547),
		Gdiplus::Color(0xff,0xfc,0xfc,0xfc),
		Gdiplus::Color(0xff,0xff,0xb3,0x76));

	// the transformation
	Gdiplus::Matrix transform;
	transform.SetElements(0,-1,17,0,-10437.2431641,496.7466736);
	gradient.MultiplyTransform(&transform,Gdiplus::MatrixOrderAppend);

	// paint
	graphics.FillPath(&gradient,&polygon);
}

----------

The data in the svg file seems to be correct, since both IE with adobe
plugin and firefox with cairo render it correctly -
( http://www.**--****.com/ )

But gdi+ brakes the gradient, the relative position of the brush to the
polygon seems not to match. Am I missing something in the conversion or
should the above C++-Code not deliver the same image? Is something
special about the above numeric values which messes up GDI+?

p.s.: If you don't want to compile the stuff to know what I am talking
about ;-) just go to
 http://www.**--****.com/ 

gradient.svg  is the svg file quoted above
gradient.emf  the product of the c++ code
gradient.jpg  a screenshot from the webbrowser 



Thanks,

Ronnie



Return to Win32 Programming

 

Who is online

Users browsing this forum: No registered users and 43 guest