?
Solved

C# - Export Panel1 and PictureBoxes to single JPG file

Posted on 2007-04-10
4
Medium Priority
?
855 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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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