团队博客-11月20日

        今天完成了用代码实现把picturebox上的照片以及个人信息内容生成到一个文件中,最后虽然没有实现理想的

结果,不过倒是实现了生成一个截屏文件同时加了一个可以更改背景照片格式并保存在相应文件夹中的功能,感觉

算不错了,当然遇到的问题主要就是怎样把picturebox上的照片以及个人信息内容生成到一个文件中。

燃尽图:

 

实现截屏功能以及更改照片格式的代码:

saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif|PNG Image|*.png";
            saveFileDialog1.Title = "Save";
            saveFileDialog1.FileName = string.Empty;
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName != "")
            {
                System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
                switch (saveFileDialog1.FilterIndex)
                {
                    case 1:
                        pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;
                    case 2:
                        this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    case 3:
                        this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
                        break;
                    case 4:
                        this.pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                        break;
                }
                fs.Close();
            }
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawRectangle(new Pen(new SolidBrush(Color.Green)), new Rectangle(Location.X - Width / 2, Location.Y - Height / 2, Width, Height));
            g.Dispose();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            int w = pictureBox1.Width;
            int h = pictureBox1.Height;
            Bitmap bm new Bitmap(w, h);
            pictureBox1.DrawToBitmap(bm, new Rectangle(0,0,w,h));//调整截屏上下
            bm.Save("E:\\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            int x = Math.Max(0, ((MouseEventArgs)e).X - Width);
            int y = Math.Max(0, ((MouseEventArgs)e).Y - Height);//调整截屏左右
            using (Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format32bppRgb))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clear(Color.White);
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.DrawImage(bm, new Rectangle(00, Width, Height),
                        new Rectangle(x, y, Width, Height), GraphicsUnit.Pixel);
                    bmp.Save("C:\\Users\\ha'se'e\\Desktop\\截屏.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    g.Dispose();
                }
            }
            bm.Dispose();

 

 private void button7_Click(object sender, EventArgs e)
        {
            PrintDialog MyPrintDg new PrintDialog();
            MyPrintDg.Document = printDocument1;
            if (MyPrintDg.ShowDialog() ==DialogResult.OK) { try
                {
                    printDocument1.Print();
                }
                catch
                {   //停止打印
                    printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs());
                }
            }       
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {           
            e.Graphics.DrawImage(pictureBox1.Image, 20,20);
        }

posted on 2018-11-20 21:03  争当博主  阅读(75)  评论(0编辑  收藏  举报

导航