1. 程式人生 > >團隊部落格-11月20日

團隊部落格-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);
        }