|
@@ -21,14 +21,18 @@ using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Imaging;
|
|
using ComPDFKit.Tool.DrawTool;
|
|
using ComPDFKit.Tool.DrawTool;
|
|
using ComPDFKitViewer.Helper;
|
|
using ComPDFKitViewer.Helper;
|
|
|
|
+using ComPDFKit.Tool.Help;
|
|
|
|
|
|
namespace Compdfkit_Tools.Edit
|
|
namespace Compdfkit_Tools.Edit
|
|
{
|
|
{
|
|
public partial class PDFImageEditControl : UserControl
|
|
public partial class PDFImageEditControl : UserControl
|
|
{
|
|
{
|
|
|
|
+ #region property
|
|
public CPDFViewerTool ToolView { get; set; }
|
|
public CPDFViewerTool ToolView { get; set; }
|
|
public ImageEditParam EditEvent { get; set; }
|
|
public ImageEditParam EditEvent { get; set; }
|
|
|
|
+
|
|
//public List<PDFEditEvent> EditMultiEvents { get; set; }
|
|
//public List<PDFEditEvent> EditMultiEvents { get; set; }
|
|
|
|
+ #endregion
|
|
|
|
|
|
public PDFImageEditControl()
|
|
public PDFImageEditControl()
|
|
{
|
|
{
|
|
@@ -37,6 +41,8 @@ namespace Compdfkit_Tools.Edit
|
|
Unloaded += PDFImageEditControl_Unloaded;
|
|
Unloaded += PDFImageEditControl_Unloaded;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #region Load unload custom control
|
|
|
|
+
|
|
private void PDFImageEditControl_Loaded(object sender, RoutedEventArgs e)
|
|
private void PDFImageEditControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
RotateUI.RotationChanged -= RotateUI_RotationChanged;
|
|
RotateUI.RotationChanged -= RotateUI_RotationChanged;
|
|
@@ -47,6 +53,15 @@ namespace Compdfkit_Tools.Edit
|
|
ToolView.SelectedDataChanged += ToolView_SelectedDataChanged;
|
|
ToolView.SelectedDataChanged += ToolView_SelectedDataChanged;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void PDFImageEditControl_Unloaded(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ RotateUI.RotationChanged -= RotateUI_RotationChanged;
|
|
|
|
+ FlipUI.FlipChanged -= FlipUI_FlipChanged;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ #region Property changed
|
|
private void ToolView_SelectedDataChanged(object sender, SelectedAnnotData e)
|
|
private void ToolView_SelectedDataChanged(object sender, SelectedAnnotData e)
|
|
{
|
|
{
|
|
if (ToolView.GetIsCropMode())
|
|
if (ToolView.GetIsCropMode())
|
|
@@ -64,7 +79,7 @@ namespace Compdfkit_Tools.Edit
|
|
pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
|
|
pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
|
|
CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
|
|
CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
|
|
imageArea.CutWithRect(newCRect);
|
|
imageArea.CutWithRect(newCRect);
|
|
-
|
|
|
|
|
|
+
|
|
SetImageThumb();
|
|
SetImageThumb();
|
|
ToolView.UpdateRender(oldRect, imageArea);
|
|
ToolView.UpdateRender(oldRect, imageArea);
|
|
editPage.EndEdit();
|
|
editPage.EndEdit();
|
|
@@ -72,21 +87,61 @@ namespace Compdfkit_Tools.Edit
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void PDFImageEditControl_Unloaded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ #region Init PDFViewer
|
|
|
|
+ public void InitWithPDFViewer(CPDFViewerTool newPDFView)
|
|
{
|
|
{
|
|
- RotateUI.RotationChanged -= RotateUI_RotationChanged;
|
|
|
|
- FlipUI.FlipChanged -= FlipUI_FlipChanged;
|
|
|
|
|
|
+ ToolView = newPDFView;
|
|
}
|
|
}
|
|
|
|
+ #endregion
|
|
|
|
|
|
|
|
+ #region public method
|
|
|
|
|
|
public void SetRotationText(float rotation)
|
|
public void SetRotationText(float rotation)
|
|
{
|
|
{
|
|
RotationTxb.Text = rotation.ToString(CultureInfo.CurrentCulture);
|
|
RotationTxb.Text = rotation.ToString(CultureInfo.CurrentCulture);
|
|
}
|
|
}
|
|
|
|
|
|
- public void InitWithPDFViewer(CPDFViewerTool newPDFView)
|
|
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ #region Image Edit
|
|
|
|
+
|
|
|
|
+ public void SetImageThumb()
|
|
{
|
|
{
|
|
- ToolView = newPDFView;
|
|
|
|
|
|
+ if (EditEvent != null)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
|
|
+
|
|
|
|
+ string path = Path.GetTempPath();
|
|
|
|
+ string uuid = Guid.NewGuid().ToString("N");
|
|
|
|
+ string imagePath = Path.Combine(path, uuid + ".tmp");
|
|
|
|
+ imageArea.ExtractImage(imagePath);
|
|
|
|
+
|
|
|
|
+ Bitmap bitmapImage = new Bitmap(imagePath);
|
|
|
|
+ MemoryStream memoryStream = new MemoryStream();
|
|
|
|
+
|
|
|
|
+ bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
|
|
|
|
+ BitmapImage imageShow = new BitmapImage();
|
|
|
|
+ imageShow.BeginInit();
|
|
|
|
+ imageShow.StreamSource = memoryStream;
|
|
|
|
+ imageShow.EndInit();
|
|
|
|
+ ImageThumbUI.Source = imageShow;
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void SetImageTransparency(double transparency)
|
|
|
|
+ {
|
|
|
|
+ ImasgeOpacitySlider.Value = transparency / 255D;
|
|
|
|
+ OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(ImasgeOpacitySlider.Value * 100)));
|
|
}
|
|
}
|
|
|
|
|
|
public void SetPDFImageEditData(ImageEditParam newEvent)
|
|
public void SetPDFImageEditData(ImageEditParam newEvent)
|
|
@@ -103,15 +158,18 @@ namespace Compdfkit_Tools.Edit
|
|
{
|
|
{
|
|
SetImageTransparency(newEvent.Transparency);
|
|
SetImageTransparency(newEvent.Transparency);
|
|
}
|
|
}
|
|
-
|
|
|
|
- if(RotationTxb!=null && newEvent!=null && newEvent.EditType == CPDFEditType.EditImage)
|
|
|
|
|
|
+
|
|
|
|
+ if (RotationTxb != null && newEvent != null && newEvent.EditType == CPDFEditType.EditImage)
|
|
{
|
|
{
|
|
- //RotationTxb.Text = newEvent.CurrentRotated.ToString(CultureInfo.CurrentCulture);
|
|
|
|
|
|
+ GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
|
|
+ RotationTxb.Text = imageArea.GetRotation().ToString();
|
|
|
|
+ //RotationTxb.Text = newEvent.Rotate.ToString(CultureInfo.CurrentCulture);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
EditEvent = newEvent;
|
|
EditEvent = newEvent;
|
|
SetImageThumb();
|
|
SetImageThumb();
|
|
}
|
|
}
|
|
|
|
+ #endregion
|
|
|
|
|
|
//public void SetPDFImageMultiEditData(List<PDFEditEvent> editEvents)
|
|
//public void SetPDFImageMultiEditData(List<PDFEditEvent> editEvents)
|
|
//{
|
|
//{
|
|
@@ -138,7 +196,7 @@ namespace Compdfkit_Tools.Edit
|
|
// ImageThumbUI.Source = null;
|
|
// ImageThumbUI.Source = null;
|
|
// }
|
|
// }
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
// if (editEvents != null && editEvents.Count > 0)
|
|
// if (editEvents != null && editEvents.Count > 0)
|
|
// {
|
|
// {
|
|
// PDFEditEvent editEvent = editEvents[0];
|
|
// PDFEditEvent editEvent = editEvents[0];
|
|
@@ -151,6 +209,8 @@ namespace Compdfkit_Tools.Edit
|
|
// EditMultiEvents = editEvents;
|
|
// EditMultiEvents = editEvents;
|
|
//}
|
|
//}
|
|
|
|
|
|
|
|
+ #region Property changed
|
|
|
|
+
|
|
private void FlipUI_FlipChanged(object sender, bool e)
|
|
private void FlipUI_FlipChanged(object sender, bool e)
|
|
{
|
|
{
|
|
GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
@@ -274,7 +334,7 @@ namespace Compdfkit_Tools.Edit
|
|
//{
|
|
//{
|
|
// foreach (PDFEditEvent editEvent in EditMultiEvents)
|
|
// foreach (PDFEditEvent editEvent in EditMultiEvents)
|
|
// {
|
|
// {
|
|
- // editEvent.Transparency = (int)(ImasgeOpacitySlider.Value * 255);
|
|
|
|
|
|
+ // editEvent.Transparency = (int)(ImageOpacitySlider.Value * 255);
|
|
// }
|
|
// }
|
|
// PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
|
|
// PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
|
|
//}
|
|
//}
|
|
@@ -332,43 +392,26 @@ namespace Compdfkit_Tools.Edit
|
|
int imageWidth = 0;
|
|
int imageWidth = 0;
|
|
int imageHeight = 0;
|
|
int imageHeight = 0;
|
|
byte[] imageData = null;
|
|
byte[] imageData = null;
|
|
-
|
|
|
|
- BitmapFrame frame = null;
|
|
|
|
- BitmapDecoder decoder = BitmapDecoder.Create(new Uri(openFileDialog.FileName), BitmapCreateOptions.None, BitmapCacheOption.Default);
|
|
|
|
- if (decoder.Frames.Count > 0)
|
|
|
|
- {
|
|
|
|
- frame = decoder.Frames[0];
|
|
|
|
- }
|
|
|
|
- if (frame != null)
|
|
|
|
- {
|
|
|
|
- imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
|
- if (frame.Format != PixelFormats.Bgra32)
|
|
|
|
- {
|
|
|
|
- FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
|
|
|
|
- covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
|
|
|
|
- }
|
|
|
|
- imageWidth = frame.PixelWidth;
|
|
|
|
- imageHeight = frame.PixelHeight;
|
|
|
|
- }
|
|
|
|
- Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
|
|
|
|
- CRect imageRect = imageArea.GetClipRect();
|
|
|
|
- if (imageArea.ReplaceImageArea(imageRect, imageData, imageWidth, imageHeight))
|
|
|
|
|
|
+ PDFHelp.ImagePathToByte(openFileDialog.FileName, ref imageData, ref imageWidth, ref imageHeight);
|
|
|
|
+
|
|
|
|
+ if (imageData != null && imageWidth > 0 && imageHeight > 0)
|
|
{
|
|
{
|
|
- PDFEditHistory editHistory = new PDFEditHistory();
|
|
|
|
- editHistory.EditPage = editPage;
|
|
|
|
- if (pdfPage != null)
|
|
|
|
|
|
+ Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
|
|
|
|
+ CRect imageRect = imageArea.GetClipRect();
|
|
|
|
+ if (imageArea.ReplaceImageArea(imageRect, imageData, imageWidth, imageHeight))
|
|
{
|
|
{
|
|
- editHistory.PageIndex = pdfPage.PageIndex;
|
|
|
|
- }
|
|
|
|
|
|
+ PDFEditHistory editHistory = new PDFEditHistory();
|
|
|
|
+ editHistory.EditPage = editPage;
|
|
|
|
+ if (pdfPage != null)
|
|
|
|
+ {
|
|
|
|
+ editHistory.PageIndex = pdfPage.PageIndex;
|
|
|
|
+ }
|
|
|
|
|
|
- ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
|
|
|
|
- SetImageThumb();
|
|
|
|
- ToolView.UpdateRender(oldRect, imageArea);
|
|
|
|
- editPage.EndEdit();
|
|
|
|
|
|
+ ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
|
|
|
|
+ SetImageThumb();
|
|
|
|
+ ToolView.UpdateRender(oldRect, imageArea);
|
|
|
|
+ editPage.EndEdit();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -379,7 +422,6 @@ namespace Compdfkit_Tools.Edit
|
|
{
|
|
{
|
|
if (ToolView != null)
|
|
if (ToolView != null)
|
|
{
|
|
{
|
|
- //需要选中图片对象
|
|
|
|
// Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
|
|
// Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
|
|
Dictionary<int, List<Bitmap>> imageDict = new Dictionary<int, List<Bitmap>>();
|
|
Dictionary<int, List<Bitmap>> imageDict = new Dictionary<int, List<Bitmap>>();
|
|
if (imageDict != null && imageDict.Count > 0)
|
|
if (imageDict != null && imageDict.Count > 0)
|
|
@@ -414,16 +456,6 @@ namespace Compdfkit_Tools.Edit
|
|
|
|
|
|
private void ImageClipBtn_Click(object sender, RoutedEventArgs e)
|
|
private void ImageClipBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
- //if(EditMultiEvents!=null && EditMultiEvents.Count>1)
|
|
|
|
- //{
|
|
|
|
- // return;
|
|
|
|
- //}
|
|
|
|
-
|
|
|
|
- //if (EditEvent != null)
|
|
|
|
- //{
|
|
|
|
- // EditEvent.ClipImage = true;
|
|
|
|
- // EditEvent.UpdatePDFEditByEventArgs();
|
|
|
|
- //}
|
|
|
|
ToolView.SetCropMode(!ToolView.GetIsCropMode());
|
|
ToolView.SetCropMode(!ToolView.GetIsCropMode());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -440,42 +472,6 @@ namespace Compdfkit_Tools.Edit
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void SetImageThumb()
|
|
|
|
- {
|
|
|
|
- if (EditEvent != null)
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
|
|
-
|
|
|
|
- string path = Path.GetTempPath();
|
|
|
|
- string uuid = Guid.NewGuid().ToString("N");
|
|
|
|
- string imagePath = Path.Combine(path, uuid + ".tmp");
|
|
|
|
- imageArea.ExtractImage(imagePath);
|
|
|
|
-
|
|
|
|
- Bitmap bitmapImage = new Bitmap(imagePath);
|
|
|
|
- MemoryStream memoryStream = new MemoryStream();
|
|
|
|
-
|
|
|
|
- bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
|
|
|
|
- BitmapImage imageShow = new BitmapImage();
|
|
|
|
- imageShow.BeginInit();
|
|
|
|
- imageShow.StreamSource = memoryStream;
|
|
|
|
- imageShow.EndInit();
|
|
|
|
- ImageThumbUI.Source = imageShow;
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void SetImageTransparency(double transparency)
|
|
|
|
- {
|
|
|
|
- ImasgeOpacitySlider.Value = transparency / 255D;
|
|
|
|
- OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(ImasgeOpacitySlider.Value * 100)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
|
|
private void GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
|
|
{
|
|
{
|
|
imageArea = null;
|
|
imageArea = null;
|
|
@@ -503,7 +499,7 @@ namespace Compdfkit_Tools.Edit
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void SetAbsRotation(double absRotation)
|
|
private void SetAbsRotation(double absRotation)
|
|
{
|
|
{
|
|
GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
|
|
@@ -527,10 +523,10 @@ namespace Compdfkit_Tools.Edit
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void RotationTxb_LostFocus(object sender, RoutedEventArgs e)
|
|
private void RotationTxb_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
- if(!double.TryParse(RotationTxb.Text, out double rotation))
|
|
|
|
|
|
+ if (!double.TryParse(RotationTxb.Text, out double rotation))
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -544,6 +540,6 @@ namespace Compdfkit_Tools.Edit
|
|
RotationTxb_LostFocus(null, null);
|
|
RotationTxb_LostFocus(null, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ #endregion
|
|
}
|
|
}
|
|
}
|
|
}
|