public static void PrintImage(string PhotoPath, string PhotoName) { //获取源图片 srcImage = new Bitmap(PhotoUpLoadDownLoad.DownLoadImage(PhotoPath, PhotoName)); if (srcImage == null) { return; } //打印预览 //PrintPreviewDialog ppd = new PrintPreviewDialog(); PrintDocument pd = new PrintDocument(); //设置边距 Margins margin = new Margins(20, 20, 20, 20); pd.DefaultPageSettings.Margins = margin; ////纸张设置默认 PaperSize pageSize = new PaperSize("Image Print", pageWidth, pageHeight); pd.DefaultPageSettings.PaperSize = pageSize; //打印事件设置 pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); //ppd.Document = pd; //ppd.ShowDialog(); try { pd.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); pd.PrintController.OnEndPrint(pd, new PrintEventArgs()); } }
// 创建工作图片,其中调用了OnNewPhoto方法来完成具体的创建工作。 private void CreateImage() { Bitmap srcImage = null; try { // 载入图片时显示进度 //Cursor.Current = Cursors.WaitCursor; //Global.Progress.Update(this, "Loading photo", 1, 2); //srcImage = new Bitmap(_photo.PhotoPath); srcImage = new Bitmap(PhotoUpLoadDownLoad.DownLoadImage(_photo.PhotoPath, _photo.PhotoName)); //Global.Progress.Update(this, "Loading photo", 2, 2); //OnNewPhoto(_photo.PhotoPath, srcImage, srcImage.RawFormat); OnNewPhoto(srcImage, srcImage.RawFormat); } catch { // an error occurred, the photo file is missing or there // is a problem with the file //Global.DisplayError(string.Format("The photo \'{0}\' could not be opened.", _photo.PhotoName), ex); //throw ex; srcImage = PhotoControl.Properties.Resources.no_photo_s; //Global.Progress.Update(this, "Loading photo", 2, 2); //OnNewPhoto(_photo.PhotoPath, srcImage, srcImage.RawFormat); OnNewPhoto(srcImage, srcImage.RawFormat); } finally { if (!(srcImage == null)) { srcImage.Dispose(); } //Global.Progress.Complete(this); //Cursor.Current = Cursors.Default; } }
public static void DeletePhoto(int PhotoID, string PhotoPath, string PhotoName) { PhotoUpLoadDownLoad.DeleteFile(PhotoPath, PhotoName); DataAccess.DeleteYj(PhotoID); }