I'm afraid I don't understand this part ot your problem. :ehh: When writing an image to an external disk file, in the vast majototy of cases, you're one of these three scenarios: The output file is entirely under your control, in which case you may pick any valid file neme you like. You store the file for further processing by another program; in this case you've either been told the required file name up-front, or you pick a name and pass it on for further processing. Finally, your code may have been passed a file handle or other file object to write the image to; in this case you won't get in touch with the file name at all anyway.
As to the rest of your problem description: So you're obtaining your graphics object for painting like this?
Code:
Graphics ^g3 = pictureBox1->CreateGraphics();
This way you're painting onto the picture box object representing the image, rather than onto the original image itself. If you're doing that the right way, in the picture box' paint event handler (in this case you'd probably better be referring to the
Graphics as
e->Graphics from inside the handler, however, rather than creating a new one), you may be able to get a representation of the processed image for saving by using the
PictureBox::DrawToBitmap() method. Otherwise your only choice (as long as you stick to painting on the screen representation rather than the actual subject image) is taking a screen shot of the processed image using the
Graphics::CopyFromScreen() method. You may technically get away with that, but it's by far the most complicated option, and why take so much effort?
Why not simply paint onto the original image directly? You can obtain a
Graphics that enables you to do that somewhat like this:
Code:
Graphics ^g3 = Graphics::FromImage(pictureBox1->Image);
I'd expect that to require few to zero changes to your existing code, especially if resolutions of the original image and its screen representation are identical. And if the resolutions differ between the two, working directly with the original may well even improve the quality of the result of your processing.
I'm not entirely sure, however, whether drawing to an image while at the same time have it displayed in an active picture box is safe. If you experience that this is problematic (or see that documented somewhere), you may
Clone() the image backing the picture box, apply your modifications to the clone, and eventually assign the clone to the PB's
Image property to display it.