Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i actually save 2 panel as one image ? currently, this is my code but it shown error : "cannot convert from system.window.form.panel to system.drawing.image" .

What I have tried:

Bitmap bitmap = new Bitmap(cap_top.Width + cap_btm.Width, Math.Max(cap_top.Height, cap_btm.Height));
using (Graphics g = Graphics.FromImage(bitmap))
{
    g.DrawImage(cap_top, 0, 0);
    g.DrawImage(cap_btm, cap_top.Width, 0);

}
Posted
Updated 12-Sep-17 17:29pm

Ummm...the error message is quite clear. Looking at the documentation for DrawImage, it does indeed expect that first parameter to be an Image, NOT a Control, which is what a Panel is.

So, the Panel controls cannot be used there. How are you supplying an image of some kind to the Panel controls? If they are Bitmap objects, you just pass those in to the DrawImage calls, not the Panel controls.
 
Share this answer
 
The error is pretty self explanatory. TO use an analogy:
Quote:
You can not fit a square peg in a round hole.

This Link however shows you how to do it with one panel: c# - Draw on Panel, save as Bitmap - Stack Overflow[^]

To do it with two Panels would be to first paint one bitmap over the other before saving.
 
Share this answer
 
How about Control.DrawToBitmap Method (Bitmap, Rectangle) (System.Windows.Forms)[^] ?
C#
Bitmap bitmap = new Bitmap(cap_top.Width + cap_btm.Width, Math.Max(cap_top.Height, cap_btm.Height));
cap_top.DrawToBitmap(bitmap, new Rectangle(0, 0, cap_top.Width, cap_top.Height));
cap_btm.DrawToBitmap(bitmap, new Rectangle(cap_top.Width, 0, cap_btm.Width, cap_btm.Height));
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900