Solved

C# - Export Panel1 and PictureBoxes to single JPG file

Posted on 2007-04-10
4
843 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

738 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