Solved

C# - Export Panel1 and PictureBoxes to single JPG file

Posted on 2007-04-10
4
828 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now