|
@@ -109,6 +109,37 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 用于判断是否更换了文件,更换了文件则需要重新计算去背功能
|
|
|
|
+ /// </summary>
|
|
|
|
+ private bool IsNewFile = false;
|
|
|
|
+
|
|
|
|
+ private BitmapSource originalimagePreviewSource;
|
|
|
|
+ private BitmapSource removeBackgroundImagePreviewSource;
|
|
|
|
+
|
|
|
|
+ private bool issRemoveBackground;
|
|
|
|
+
|
|
|
|
+ public bool IsRemoveBackground
|
|
|
|
+ {
|
|
|
|
+ get { return issRemoveBackground; }
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ SetProperty(ref issRemoveBackground, value);
|
|
|
|
+ if (issRemoveBackground)
|
|
|
|
+ {
|
|
|
|
+ if (IsNewFile)
|
|
|
|
+ {
|
|
|
|
+ removeBackgroundImagePreviewSource = ToBitmapImage(KnockOutGzf());
|
|
|
|
+ }
|
|
|
|
+ ImagePreviewSource = removeBackgroundImagePreviewSource;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ImagePreviewSource = originalimagePreviewSource;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private C_TEXTSTAMP_SHAPE shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
|
|
private C_TEXTSTAMP_SHAPE shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
|
|
|
|
|
|
@@ -127,11 +158,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
}
|
|
}
|
|
|
|
|
|
public string SaveToPath { get; private set; }
|
|
public string SaveToPath { get; private set; }
|
|
|
|
+ public string RemoveBackgroundSaveToPath { get; private set; }
|
|
public string StampTextDate { get; private set; }
|
|
public string StampTextDate { get; private set; }
|
|
public int StampWidth { get; private set; }
|
|
public int StampWidth { get; private set; }
|
|
public int StampHeight { get; private set; }
|
|
public int StampHeight { get; private set; }
|
|
public StampType Type { get; private set; }
|
|
public StampType Type { get; private set; }
|
|
-
|
|
|
|
|
|
+ private Bitmap bitmapProxy;
|
|
public void SetStampStyle(int index)
|
|
public void SetStampStyle(int index)
|
|
{
|
|
{
|
|
RadioButtonIndex = index;
|
|
RadioButtonIndex = index;
|
|
@@ -324,8 +356,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
{
|
|
{
|
|
App.CachePath.AddToDeleteFiles(SaveToPath);
|
|
App.CachePath.AddToDeleteFiles(SaveToPath);
|
|
}
|
|
}
|
|
|
|
+ IsNewFile = true;
|
|
SaveToPath = path;
|
|
SaveToPath = path;
|
|
- ImagePreviewSource = targetBitmap;
|
|
|
|
|
|
+ ImagePreviewSource= originalimagePreviewSource = targetBitmap;
|
|
StampWidth = targetBitmap.PixelWidth;
|
|
StampWidth = targetBitmap.PixelWidth;
|
|
StampHeight = targetBitmap.PixelHeight;
|
|
StampHeight = targetBitmap.PixelHeight;
|
|
Type = StampType.IMAGE_STAMP;
|
|
Type = StampType.IMAGE_STAMP;
|
|
@@ -346,7 +379,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
App.CachePath.AddToDeleteFiles(SaveToPath);
|
|
App.CachePath.AddToDeleteFiles(SaveToPath);
|
|
}
|
|
}
|
|
SaveToPath = path;
|
|
SaveToPath = path;
|
|
- ImagePreviewSource = targetBitmap;
|
|
|
|
|
|
+ IsNewFile = true;
|
|
|
|
+ ImagePreviewSource = originalimagePreviewSource = targetBitmap;
|
|
StampWidth = targetBitmap.PixelWidth;
|
|
StampWidth = targetBitmap.PixelWidth;
|
|
StampHeight = targetBitmap.PixelHeight;
|
|
StampHeight = targetBitmap.PixelHeight;
|
|
Type = StampType.IMAGE_STAMP;
|
|
Type = StampType.IMAGE_STAMP;
|
|
@@ -358,6 +392,64 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
SaveToPath = "";
|
|
SaveToPath = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 去除白底
|
|
|
|
+ /// </summary>
|
|
|
|
+ public Bitmap KnockOutGzf()
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ System.Drawing.Image image = System.Drawing.Image.FromFile(SaveToPath);
|
|
|
|
+ bitmapProxy = new Bitmap(image);
|
|
|
|
+ for (int i = 0; i < bitmapProxy.Width; i++)
|
|
|
|
+ {
|
|
|
|
+ for (int j = 0; j < bitmapProxy.Height; j++)
|
|
|
|
+ {
|
|
|
|
+ System.Drawing.Color c = bitmapProxy.GetPixel(i, j);
|
|
|
|
+ if (!(c.R < 240 || c.G < 240 || c.B < 240))
|
|
|
|
+ {
|
|
|
|
+ bitmapProxy.SetPixel(i, j, System.Drawing.Color.Transparent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return bitmapProxy;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 将 Bitmap 转化为 BitmapSource
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="bmp"/>要转换的 Bitmap
|
|
|
|
+ /// <returns>转换后的 BitmapImage</returns>
|
|
|
|
+ private BitmapImage ToBitmapImage(System.Drawing.Bitmap bmp)
|
|
|
|
+ {
|
|
|
|
+ System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
|
|
+ bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
|
+
|
|
|
|
+ BitmapImage image = new BitmapImage();
|
|
|
|
+ image.BeginInit();
|
|
|
|
+ image.StreamSource = ms;
|
|
|
|
+ image.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
|
+ image.EndInit();
|
|
|
|
+ //编码,缓存到本地
|
|
|
|
+ string path = App.CachePath.CustomStampPath;
|
|
|
|
+ string name = Guid.NewGuid().ToString();
|
|
|
|
+ BitmapEncoder encoder = new PngBitmapEncoder();
|
|
|
|
+ encoder.Frames.Add(BitmapFrame.Create(image));
|
|
|
|
+ path = System.IO.Path.Combine(path, name);
|
|
|
|
+ using (FileStream stream = new FileStream(path, FileMode.Create))
|
|
|
|
+ {
|
|
|
|
+ encoder.Save(stream);
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrEmpty(RemoveBackgroundSaveToPath))
|
|
|
|
+ {
|
|
|
|
+ App.CachePath.AddToDeleteFiles(RemoveBackgroundSaveToPath);
|
|
|
|
+ }
|
|
|
|
+ RemoveBackgroundSaveToPath = path;
|
|
|
|
+ IsNewFile = false;
|
|
|
|
+ return image;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
{
|
|
if (parameters != null)
|
|
if (parameters != null)
|