Vignesh_The King

Hi guys ,

i hav a code that loads an image onto a picture box and render graphics on it ..

but im not able to save the image with the graphics in to a file ....

when i call the image->save() function it show null ptr .

can any one help me with it....




Re: Visual C++ Express Edition save graphics on an image to a file

JohnWein

Are you using graphics.fromimage to do your drawing





Re: Visual C++ Express Edition save graphics on an image to a file

nobugz

You haven't set the Image property, you're probably drawing the image with the Paint event. Just use your painting code to draw both to the control and to a bitmap. For example:

void RenderImage(Graphics^ gr) {
// Draw your image here
//...
}
System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
RenderImage(e->Graphics);
}
System::Void btnSave_Click(System::Object^ sender, System::EventArgs^ e) {
Bitmap^ bmp = gcnew Bitmap(panel1->Width, panel1->Height);
Graphics^ gr = Graphics::FromImage(bmp);
RenderImage(gr);
bmp->Save("test.png");
delete bmp;
}