Problem w. Rectangle in DrawImage

Jan 7, 2011 at 11:39am
Hello forum,
I'm trying to work with some alpha blending of images with GDI+, but I get errors.

g.DrawImage(&music, new Rectangle(x_pos, y_pos, x_pos+56, y_pos+56) ,x_pos, y_pos, 56, 56, UnitPixel, &imgattr);

It says the following errors about the Rectangle:

1
2
3
1>d:\dokumenter\programmering\visual c++\media player\media player\flow_menu.h(132): error C2061: syntax error : identifier 'Rectangle'
1>d:\dokumenter\programmering\visual c++\media player\media player\flow_menu.h(132): error C2143: syntax error : missing ';' before ')'
1>d:\dokumenter\programmering\visual c++\media player\media player\flow_menu.h(132): error C2143: syntax error : missing ';' before ')'


Any solutions to this problem?

Regards,

Simon H.A.
Jan 7, 2011 at 1:30pm
Compiler can't able to find definition of Rectangle.
please check the following,
1. Whether header file included or not where Rectangle() definition is there.
2. Check corresponding header file path added in Include Directories (-I).

NOTE : First find which header file holds Rectangle() definition
Jan 9, 2011 at 9:38pm
I tried to find the declaration of the Rectangle and it said it was in WinGDI.h.
The problem is, that I have already included it...
Jan 10, 2011 at 12:53am
Rectangle is a function - It most likely should be a RECT structure.
have you checked the function information on MSDN??
Jan 10, 2011 at 8:12am
I've checked on MSDN, and it says it needs a Rectangle.

1
2
3
4
5
6
7
8
9
10
11
public:
void DrawImage(
	Image^ image, 
	Rectangle destRect, 
	int srcX, 
	int srcY, 
	int srcWidth, 
	int srcHeight, 
	GraphicsUnit srcUnit, 
	ImageAttributes^ imageAttr
)

Jan 10, 2011 at 8:44am
Point me at the msdn link where you got that information from - there is some confusion here.
You maybe reading the wrong funtion prototype on msdn.
But while we are sorting that out - see if the following helps:

1
2
Rect rect(x_pos, y_pos, x_pos+56, y_pos+56); //create a Rect structure
g.DrawImage((&music, & rect, x_pos, y_pos, 56, 56, UnitPixel, &imgattr);





**Rect is in the Gdiplus namespace - but I think you already have written a using namesace Gdiplus directive **
Last edited on Jan 10, 2011 at 9:34am
Jan 10, 2011 at 9:36am
No luck in the changed code:
1
2
d:\dokumenter\programmering\visual c++\media player\media player\flow_menu.h(139): error C2664: 'Gdiplus::Status Gdiplus::Graphics::DrawImage(Gdiplus::Image *,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::REAL,Gdiplus::Unit)' : cannot convert parameter 2 from 'Gdiplus::Rect *' to 'Gdiplus::REAL'
1>          There is no context in which this conversion is possible


Here is the link for the information: http://msdn.microsoft.com/en-us/library/ms142046.aspx
Jan 10, 2011 at 9:57am
When I was looking at the GDIplus stuff, that DrawImage function has 16 overloads.
You may need to be a bit more precise in our choice and quantity of parameters.
Jan 10, 2011 at 10:03am
I choose the overload because I was looking on a tutorial on how to use alphablend with images. He used that function overload.

Link: http://www.codeproject.com/KB/GDI-plus/AlphaBlending.aspx
Jan 10, 2011 at 10:19am
We can try;


g.DrawImage((&music, & rect, x_pos, y_pos, 56, 56, UnitPixel, &imgattr, NULL, NULL );

I'll look at the link in the meantime
Jan 10, 2011 at 11:01am
Damn this is anyoing... still complaining :S
Jan 10, 2011 at 11:03am
You could dump the code on pastebin or something - and the forum could have a look and try to debug it.
Jan 10, 2011 at 11:17am
Hmm... everything works besides this part. I'm considering changing to another graphic libary with hardware acceleration, unless there is another way to do alpha blending with GDI+?
Topic archived. No new replies allowed.