dumbquestion
October 6th, 2004, 10:06 PM
Hi there. I've tried looking around previous posts on BitBlt's, but was unable to figure out the error in my code. I'm trying to save an entire form's graphics to a .jpg file using BitBlt. I have a menuItem_Click that calls the code below to open a file and then save the form to .jpg format.
private: System::Void menuItem8_Click(System::Object * sender, System::EventArgs * e)
{
if (saveFileDialog1->ShowDialog() == DialogResult::OK)
{
System::IO::StreamWriter * sw = new System::IO::StreamWriter(saveFileDialog1->FileName);
Graphics *g1 = CreateGraphics();
Image *MyImage = new Bitmap(this->ClientRectangle.Width,this->ClientRectangle.Height,g1);
Graphics *g2 = Graphics::FromImage(MyImage);
IntPtr dc1 = g1->GetHdc();
IntPtr dc2 = g2->GetHdc();
BitBlt(dc2,0,0,this->ClientRectangle.Width,this->ClientRectangle.Height,dc1,0,0,SRCCOPY);
g1->ReleaseHdc(dc1);
g2->ReleaseHdc(dc2);
MyImage->Save(saveFileDialog1->FileName,Imaging::ImageFormat::get_Jpeg());
}
}
When I attempt to compile, I get the following errors:
'SRCCOPY' : undeclared identifier
'BitBlt' : redefinition; previous definition was a 'formerly unknown identifier'
When I double-click on the second error message, the "WinGDI.h" file is opened and the error points to a line containing:
WINGDIAPI BOOL WINAPI BitBlt( IN HDC, IN int, IN int, IN int, IN int, IN HDC, IN int, IN int, IN DWORD);
I'm a bit lost here. I've tried playing around with DllImport methods, but the examples I saw were for C#, not C++ .NET.
Am I missing something here? Any suggestions? Thanks a lot!
private: System::Void menuItem8_Click(System::Object * sender, System::EventArgs * e)
{
if (saveFileDialog1->ShowDialog() == DialogResult::OK)
{
System::IO::StreamWriter * sw = new System::IO::StreamWriter(saveFileDialog1->FileName);
Graphics *g1 = CreateGraphics();
Image *MyImage = new Bitmap(this->ClientRectangle.Width,this->ClientRectangle.Height,g1);
Graphics *g2 = Graphics::FromImage(MyImage);
IntPtr dc1 = g1->GetHdc();
IntPtr dc2 = g2->GetHdc();
BitBlt(dc2,0,0,this->ClientRectangle.Width,this->ClientRectangle.Height,dc1,0,0,SRCCOPY);
g1->ReleaseHdc(dc1);
g2->ReleaseHdc(dc2);
MyImage->Save(saveFileDialog1->FileName,Imaging::ImageFormat::get_Jpeg());
}
}
When I attempt to compile, I get the following errors:
'SRCCOPY' : undeclared identifier
'BitBlt' : redefinition; previous definition was a 'formerly unknown identifier'
When I double-click on the second error message, the "WinGDI.h" file is opened and the error points to a line containing:
WINGDIAPI BOOL WINAPI BitBlt( IN HDC, IN int, IN int, IN int, IN int, IN HDC, IN int, IN int, IN DWORD);
I'm a bit lost here. I've tried playing around with DllImport methods, but the examples I saw were for C#, not C++ .NET.
Am I missing something here? Any suggestions? Thanks a lot!