12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Media.Imaging;
- using System.Windows;
- using PDF_Office.Model.EditTools.Background;
- using PDF_Office.Model.EditTools.Watermark;
- namespace PDF_Office.Helper
- {
- public static class EditToolsHelper
- {
- public static byte[] ConvertColor(string color)
- {
- byte[] rgb_array = new byte[] { 0, 0, 0 };
- rgb_array[0] = (byte)(color[1] * 15 + color[2]);
- rgb_array[1] = (byte)(color[3] * 15 + color[4]);
- rgb_array[2] = (byte)(color[5] * 15 + color[6]);
- return rgb_array;
- }
- public static void ChooseFile(string filePath,ref BackgroundInfo backgroundInfo)
- {
- using (FileStream fileData = File.OpenRead(filePath))
- {
- string fileExt = Path.GetExtension(filePath).ToLower();
- BitmapFrame frame = null;
- BitmapDecoder decoder = BitmapDecoder.Create(fileData, BitmapCreateOptions.None, BitmapCacheOption.Default);
- if (decoder != null && decoder.Frames.Count > 0)
- {
- frame = decoder.Frames[0];
- }
- if (frame != null)
- {
- backgroundInfo.ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- backgroundInfo.ImageWidth = frame.PixelWidth;
- backgroundInfo.ImageHeight = frame.PixelHeight;
- frame.CopyPixels(backgroundInfo.ImageArray, frame.PixelWidth * 4, 0);
- #if DEBUG
- Trace.WriteLine("width :" + backgroundInfo.ImageWidth);
- Trace.WriteLine("height :" + backgroundInfo.ImageHeight);
- #endif
- }
- }
- }
- public static void ChooseFile(string filePath, ref WatermarkInfo watermarkInfo)
- {
- using (FileStream fileData = File.OpenRead(filePath))
- {
- string fileExt = Path.GetExtension(filePath).ToLower();
- BitmapFrame frame = null;
- BitmapDecoder decoder = BitmapDecoder.Create(fileData, BitmapCreateOptions.None, BitmapCacheOption.Default);
- if (decoder != null && decoder.Frames.Count > 0)
- {
- frame = decoder.Frames[0];
- }
- if (frame != null)
- {
- watermarkInfo.ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- watermarkInfo.ImageWidth = frame.PixelWidth;
- watermarkInfo.ImageHeight = frame.PixelHeight;
- frame.CopyPixels(watermarkInfo.ImageArray, frame.PixelWidth * 4, 0);
- #if DEBUG
- Trace.WriteLine("width :" + watermarkInfo.ImageWidth);
- Trace.WriteLine("height :" + watermarkInfo.ImageHeight);
- #endif
- }
- }
- }
- }
- }
|