大家好,我想在C#中把panel的内容全部旋转90度后打印,该如何处理?????

解决方案 »

  1.   

    把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();        }
      

  2.   

    如果不保存图像直接打印,你可以把myImage对象传给PrintDocument
    然后直接打印出myImage
      

  3.   

    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();        }
      

  4.   

    TO gxingmin:这样保存下来的a。jpg怎么是空的,看不到panel上面的控件
      

  5.   

    下面是我的代码:           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();
                }
      

  6.   

    不会啊,我保存下来图片有各种控件啊,panel里什么样,保存下来就什么(只不过旋转了90度)
      

  7.   

    TO gxingmin;请帮我看看我的代码是否有问题?
      

  8.   

    看你代码,没打印memImage啊
    在打印之前不要把memImage释放掉
      

  9.   

    有这么一句 
    memoryImage = (Bitmap)memImage.Clone();
      

  10.   

    你用这段代码看看效果
    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));
            }