c# 我想把panel旋转90度后打印!!??? 大家好,我想在C#中把panel的内容全部旋转90度后打印,该如何处理????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把panel1里的内容旋转90度保存图片打印[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll ")] private static extern bool BitBlt( IntPtr hdcDest, // handle to destination DC int nXDest, // x-coord of destination upper-left corner int nYDest, // y-coord of destination upper-left corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle IntPtr hdcSrc, // handle to source DC int nXSrc, // x-coordinate of source upper-left corner int nYSrc, // y-coordinate of source upper-left corner System.Int32 dwRop // raster operation code ); private void button1_Click(object sender, EventArgs e) { Graphics g1 = panel1.CreateGraphics(); Image myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1); Graphics g2 = Graphics.FromImage(myImage); IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); myImage.RotateFlip(RotateFlipType.Rotate90FlipNone); myImage.Save("c:\\a.jpg"); g1.Dispose(); } 如果不保存图像直接打印,你可以把myImage对象传给PrintDocument然后直接打印出myImage C#代码:请参考执行。[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll ")] private static extern bool BitBlt( IntPtr hdcDest, // handle to destination DC int nXDest, // x-coord of destination upper-left corner int nYDest, // y-coord of destination upper-left corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle IntPtr hdcSrc, // handle to source DC int nXSrc, // x-coordinate of source upper-left corner int nYSrc, // y-coordinate of source upper-left corner System.Int32 dwRop // raster operation code ); private void button1_Click(object sender, EventArgs e) { Graphics g1 = panel1.CreateGraphics(); Image myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1); Graphics g2 = Graphics.FromImage(myImage); IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); myImage.RotateFlip(RotateFlipType.Rotate90FlipNone); myImage.Save("c:\\a.jpg"); g1.Dispose(); } TO gxingmin:这样保存下来的a。jpg怎么是空的,看不到panel上面的控件 下面是我的代码: Graphics graphic = panel2.CreateGraphics(); Size s = panel2.Size; Bitmap memImage = new Bitmap(s.Width, s.Height, graphic); Graphics memGraphic = Graphics.FromImage(memImage); IntPtr dc1 = graphic.GetHdc(); IntPtr dc2 = memGraphic.GetHdc(); BitBlt(dc2, 0, 0, panel2.Width, panel2.Height,dc1, 0, 0, 13369376); memoryImage = (Bitmap)memImage.Clone(); graphic.ReleaseHdc(dc1); memGraphic.ReleaseHdc(dc2); graphic.Dispose(); memGraphic.Dispose(); memImage.Dispose(); //***************************** PageSetupDialog mypgDialog = new PageSetupDialog(); mypgDialog.Document = printDocument1; try { mypgDialog.ShowDialog(); } catch { printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs()); } //***************************** PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = printDocument1; dlg.Document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("cardc", 324, 204); if (dlg.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } 不会啊,我保存下来图片有各种控件啊,panel里什么样,保存下来就什么(只不过旋转了90度) TO gxingmin;请帮我看看我的代码是否有问题? 看你代码,没打印memImage啊在打印之前不要把memImage释放掉 有这么一句 memoryImage = (Bitmap)memImage.Clone(); 你用这段代码看看效果Bitmap myImage; private void button1_Click(object sender, EventArgs e) { Graphics g1 = panel1.CreateGraphics(); myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1); Graphics g2 = Graphics.FromImage(myImage); IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); myImage.RotateFlip(RotateFlipType.Rotate90FlipNone); PageSetupDialog mypgDialog = new PageSetupDialog(); mypgDialog.Document = printDocument1; try { mypgDialog.ShowDialog(); } catch { printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs()); } //***************************** PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = printDocument1; dlg.Document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("cardc", 324, 204); if (dlg.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } g1.Dispose(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(myImage, new Point(10, 10)); } WPF确定一个控件在窗口中的坐标位置 PDF复制为表粘贴到C#窗体文本框中显示乱码 FtpWebRequest问题~错误信息为“请求的URI对此FTP命令无效” 代码执行的问题。.NET C# Control 问题 如何获取前一页的URL地址,而前一页有弹出alert提示框? c# 窗体和对话框的区别 一个整形是4个字节,怎样用C#得到这四个字节? 怎么判断字符串里是否存在数字呢? 借借这里的人气 按钮模拟 Ctrl+Shift键 控制台程序怎样才能在一行输出?
[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll ")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void button1_Click(object sender, EventArgs e)
{
Graphics g1 = panel1.CreateGraphics();
Image myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1);
Graphics g2 = Graphics.FromImage(myImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
myImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
myImage.Save("c:\\a.jpg"); g1.Dispose(); }
然后直接打印出myImage
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void button1_Click(object sender, EventArgs e)
{
Graphics g1 = panel1.CreateGraphics();
Image myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1);
Graphics g2 = Graphics.FromImage(myImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
myImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
myImage.Save("c:\\a.jpg"); g1.Dispose(); }
Size s = panel2.Size;
Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panel2.Width, panel2.Height,dc1, 0, 0, 13369376);
memoryImage = (Bitmap)memImage.Clone(); graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
graphic.Dispose();
memGraphic.Dispose();
memImage.Dispose();
//*****************************
PageSetupDialog mypgDialog = new PageSetupDialog();
mypgDialog.Document = printDocument1;
try
{
mypgDialog.ShowDialog();
}
catch
{
printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs());
}
//***************************** PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Document = printDocument1;
dlg.Document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("cardc", 324, 204);
if (dlg.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
}
在打印之前不要把memImage释放掉
memoryImage = (Bitmap)memImage.Clone();
Bitmap myImage;
private void button1_Click(object sender, EventArgs e)
{
Graphics g1 = panel1.CreateGraphics();
myImage = new Bitmap(this.panel1.Width, this.panel1.Height, g1);
Graphics g2 = Graphics.FromImage(myImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.panel1.Width, this.panel1.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
myImage.RotateFlip(RotateFlipType.Rotate90FlipNone); PageSetupDialog mypgDialog = new PageSetupDialog();
mypgDialog.Document = printDocument1; try
{
mypgDialog.ShowDialog();
}
catch
{
printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs());
}
//***************************** PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = printDocument1;
dlg.Document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("cardc", 324, 204); if (dlg.ShowDialog() == DialogResult.OK)
{
printDocument1.Print();
} g1.Dispose(); }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(myImage, new Point(10, 10));
}