Solved

C# - Export Panel1 and PictureBoxes to single JPG file

Posted on 2007-04-10
4
840 Views
Last Modified: 2007-04-11
Hi guys 'n gals,

I wanted to know how would I go about converting a panel along with all the PictureBox's inside it into a Jpg file. Basically, I have a few PictureBoxes laid out on a Panel, and I want to be able to Export what it looks like as a JPG image to file.

Anybody able to help?


Cheers!
0
Comment
Question by:Cyber-Drugs
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
Yttribium earned 500 total points
ID: 18887623
Try this:
Create a button and use this:
(for anyone else that wants to use a similar solution, TransparentPictureBox is a class that's similar to PictureBox (but not inherited) Long story, it's from a previous question by Cyber-drugs.  You should probably replace this by any control you wish to "save" to file like this:


            private void button1_Click(object sender, EventArgs e)
            {
                  System.Drawing.Graphics g = Graphics.FromHwnd(this.panel1.Handle);
                  Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, g);

                  Graphics gfx;
                  Brush b = Brushes.White;
                  
                  gfx = Graphics.FromImage(bmp);
                  
                  gfx.FillRectangle(b, new Rectangle(0, 0, panel1.Width, panel1.Height));
                  foreach (TransparentPictureBox tpb in panel1.Controls)
                  {
                        gfx.DrawImage(tpb.Image, tpb.Location);
                  }
//Make this your own directory etc
                  bmp.Save(@"C:\BMPTest.bmp");

            }
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18887640
Oh yes, oops. it's saving as BMP.

Replace last line by:

//C:\test.jpg, must just be what ever you want, dynamically preferbly
bmp.Save(@"C:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18887879
A lot simpler than I thought it was going to be, cheers again!!
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18889212
you can remove the first line
System.Drawing.Graphics g = Graphics.FromHwnd(this.panel1.Handle);

Forgot to do that, was trying to do something else with this.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question