Solved

C# - Export Panel1 and PictureBoxes to single JPG file

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

14 Experts available now in Live!

Get 1:1 Help Now