private void ReconstructExifInfoCache() { OnChanging(); ++suppressChangeEvents; exifIdToExifInfo.Clear(); string[] exifKeys = GetKeys(ExifSectionName); string[] piBlobs = new string[exifKeys.Length]; for (int i = 0; i < exifKeys.Length; ++i) { piBlobs[i] = GetValue(ExifSectionName, exifKeys[i]); this.RemoveValue(ExifSectionName, exifKeys[i]); } foreach (string piBlob in piBlobs) { PropertyItem pi = PdnGraphics.DeserializePropertyItem(piBlob); AddExifValues(new PropertyItem[] { pi }); } --suppressChangeEvents; OnChanged(); }
public static PdnGraphicsPath Combine(PdnGraphicsPath subjectPath, CombineMode combineMode, PdnGraphicsPath clipPath) { switch (combineMode) { case CombineMode.Complement: return(Combine(clipPath, CombineMode.Exclude, subjectPath)); case CombineMode.Replace: return(clipPath.Clone()); case CombineMode.Xor: case CombineMode.Intersect: case CombineMode.Union: case CombineMode.Exclude: if (subjectPath.IsEmpty && clipPath.IsEmpty) { return(new PdnGraphicsPath()); // empty path } else if (subjectPath.IsEmpty) { switch (combineMode) { case CombineMode.Xor: case CombineMode.Union: return(clipPath.Clone()); case CombineMode.Intersect: case CombineMode.Exclude: return(new PdnGraphicsPath()); default: throw new InvalidEnumArgumentException(); } } else if (clipPath.IsEmpty) { switch (combineMode) { case CombineMode.Exclude: case CombineMode.Xor: case CombineMode.Union: return(subjectPath.Clone()); case CombineMode.Intersect: return(new PdnGraphicsPath()); default: throw new InvalidEnumArgumentException(); } } else { GraphicsPath resultPath = PdnGraphics.ClipPath(subjectPath, combineMode, clipPath); return(new PdnGraphicsPath(resultPath)); } default: throw new InvalidEnumArgumentException(); } }
public static void LoadProperties(Image dstImage, Document srcDoc) { Bitmap asBitmap = dstImage as Bitmap; if (asBitmap != null) { // Sometimes GDI+ does not honor the resolution tags that we // put in manually via the EXIF properties. float dpiX; float dpiY; switch (srcDoc.DpuUnit) { case MeasurementUnit.Centimeter: dpiX = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuX); dpiY = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuY); break; case MeasurementUnit.Inch: dpiX = (float)srcDoc.DpuX; dpiY = (float)srcDoc.DpuY; break; default: case MeasurementUnit.Pixel: dpiX = 1.0f; dpiY = 1.0f; break; } try { asBitmap.SetResolution(dpiX, dpiY); } catch (Exception) { // Ignore error } } Metadata metaData = srcDoc.Metadata; foreach (string key in metaData.GetKeys(Metadata.ExifSectionName)) { string blob = metaData.GetValue(Metadata.ExifSectionName, key); PropertyItem pi = PdnGraphics.DeserializePropertyItem(blob); try { dstImage.SetPropertyItem(pi); } catch (ArgumentException) { // Ignore error: the image does not support property items } } }
public static PropertyItem CreatePropertyItem(short id, ExifTagType type, byte[] data) { PropertyItem pi = PdnGraphics.CreatePropertyItem(); pi.Id = id; pi.Type = (short)type; pi.Len = data.Length; pi.Value = (byte[])data.Clone(); return(pi); }
public static void LoadProperties(Image dstImage, Document srcDoc, Func <System.Drawing.Imaging.PropertyItem, bool> selectorFn) { Bitmap bitmap = dstImage as Bitmap; if (bitmap != null) { float dpuX; float dpuY; switch (srcDoc.DpuUnit) { case MeasurementUnit.Inch: dpuX = (float)srcDoc.DpuX; dpuY = (float)srcDoc.DpuY; break; case MeasurementUnit.Centimeter: dpuX = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuX); dpuY = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuY); break; default: dpuX = 1f; dpuY = 1f; break; } try { bitmap.SetResolution(dpuX, dpuY); } catch (Exception) { } } Metadata metadata = srcDoc.Metadata; foreach (string str in metadata.GetKeys("$exif")) { System.Drawing.Imaging.PropertyItem arg = PdnGraphics.DeserializePropertyItem(metadata.GetValue("$exif", str)); if (selectorFn(arg)) { try { dstImage.SetPropertyItem(arg); } catch (ArgumentException) { } } } }
protected override void OnPaint(PaintEventArgs e) { if (this.surface != null) { PdnRegion clipRegion = null; Rectangle[] rects = this.realUpdateRects; if (rects == null) { clipRegion = new PdnRegion(e.Graphics.Clip, true); clipRegion.Intersect(e.ClipRectangle); rects = clipRegion.GetRegionScansReadOnlyInt(); } if (this.justPaintWhite > 0) { PdnGraphics.FillRectangles(e.Graphics, Color.White, rects); Invalidate(); } else { foreach (Rectangle rect in rects) { if (e.Graphics.IsVisible(rect)) { PaintEventArgs2 e2 = new PaintEventArgs2(e.Graphics, rect); OnPaintImpl(e2); } } } if (clipRegion != null) { clipRegion.Dispose(); clipRegion = null; } } if (this.justPaintWhite > 0) { --this.justPaintWhite; } base.OnPaint(e); }
private void OnPaintImpl(PaintEventArgs2 e) { using (Surface doubleBuffer = GetDoubleBuffer(e.ClipRectangle.Size)) { using (RenderArgs renderArgs = new RenderArgs(doubleBuffer)) { OnPrePaint(e); DrawArea(renderArgs, e.ClipRectangle.Location); OnPainted(e); IntPtr tracking; Point childOffset; Size parentSize; doubleBuffer.GetDrawBitmapInfo(out tracking, out childOffset, out parentSize); PdnGraphics.DrawBitmap(e.Graphics, e.ClipRectangle, e.Graphics.Transform, tracking, childOffset.X, childOffset.Y); } } }
public static void LoadProperties(Image dstImage, Document srcDoc) { Metadata metaData = srcDoc.Metadata; foreach (string key in metaData.GetKeys(Metadata.ExifSectionName)) { string blob = metaData.GetValue(Metadata.ExifSectionName, key); PropertyItem pi = PdnGraphics.DeserializePropertyItem(blob); try { dstImage.SetPropertyItem(pi); } catch (ArgumentException) { // Ignore error: the image does not support property items } } }
public override unsafe MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { Surface result = null; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { bool flag = transaction.TryGetRawNativeData(8, delegate(UnsafeBufferLock buffer) { Size size; byte *pBitmapInfo = (byte *)buffer.Address; int ncbBitmapInfo = (int)buffer.Size; if (PdnGraphics.TryGetBitmapInfoSize(pBitmapInfo, ncbBitmapInfo, out size)) { Surface disposeMe = new Surface(size.Width, size.Height); bool flag = false; try { using (Bitmap bitmap = disposeMe.CreateAliasedBitmap(true)) { flag = PdnGraphics.TryCopyFromBitmapInfo(bitmap, pBitmapInfo, ncbBitmapInfo); } disposeMe.DetectAndFixDishonestAlpha(); } finally { if (flag) { result = disposeMe; } else { DisposableUtil.Free <Surface>(ref disposeMe); } } } }); } return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref result)); }
private static unsafe Surface GetClipboardImageAsSurface(IWin32Window currentWindow, IPdnDataObject clipData) { Image image = null; Surface surface = null; if (((image == null) && (surface == null)) && clipData.GetDataPresent(PdnDataObjectFormats.FileDrop)) { try { string[] strArray = null; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { strArray = transaction.TryGetFileDropData(); } if ((strArray != null) && (strArray.Length == 1)) { string fileName = strArray[0]; if (IsImageFileName(fileName) && File.Exists(fileName)) { image = Image.FromFile(fileName); surface = Surface.CopyFromGdipImage(image, false); image.Dispose(); image = null; } } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if (((image == null) && (surface == null)) && clipData.GetDataPresent(PdnDataObjectFormats.Dib, true)) { try { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction2 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { bool flag = transaction2.TryGetRawNativeData(8, delegate(UnsafeBufferLock buffer) { Size size; byte *pBitmapInfo = (byte *)buffer.Address; int ncbBitmapInfo = (int)buffer.Size; if (PdnGraphics.TryGetBitmapInfoSize(pBitmapInfo, ncbBitmapInfo, out size)) { surface = new Surface(size.Width, size.Height); bool flag = false; try { using (Bitmap bitmap = surface.CreateAliasedBitmap(true)) { flag = PdnGraphics.TryCopyFromBitmapInfo(bitmap, pBitmapInfo, ncbBitmapInfo); } surface.DetectAndFixDishonestAlpha(); } finally { if ((surface != null) && !flag) { surface.Dispose(); surface = null; } } } }); } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if (((image == null) && (surface == null)) && (clipData.GetDataPresent(PdnDataObjectFormats.Bitmap, true) || clipData.GetDataPresent(PdnDataObjectFormats.EnhancedMetafile, true))) { try { image = clipData.GetData(PdnDataObjectFormats.Bitmap, true) as Image; } catch (OutOfMemoryException) { throw; } catch (Exception) { } if (image == null) { try { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction3 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { image = transaction3.TryGetEmf(); Image image1 = image; } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } } if (((image == null) && (surface == null)) && clipData.GetDataPresent("PNG", false)) { try { bool flag2 = false; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction4 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { uint formatID = PaintDotNet.SystemLayer.Clipboard.RegisterFormat("PNG"); flag2 = transaction4.TryGetRawNativeData(formatID, delegate(Stream stream) { image = Image.FromStream(stream, false, true); }); } if (flag2 && (image != null)) { surface = Surface.CopyFromGdipImage(image, false); DisposableUtil.Free <Image>(ref image); } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if ((surface != null) && (image != null)) { throw new InternalErrorException("both surface and image are non-null"); } if ((surface == null) && (image != null)) { surface = Surface.CopyFromGdipImage(image, true); } return(surface); }
public void AddExifValues(PropertyItem[] items) { if (items.Length == 0) { return; } short id = unchecked ((short)items[0].Id); for (int i = 1; i < items.Length; ++i) { if (unchecked ((short)items[i].Id) != id) { throw new ArgumentException("all PropertyItem instances in items must have the same id"); } } string[] names = new string[items.Length]; OnChanging(); ++suppressChangeEvents; for (int i = 0; i < items.Length; ++i) { names[i] = GetUniqueExifName(); string blob = PdnGraphics.SerializePropertyItem(items[i]); SetValueConcrete(ExifSectionName, names[i], blob); } object idObj = (object)id; // avoid boxing twice ExifInfo info = (ExifInfo)this.exifIdToExifInfo[idObj]; if (info == null) { PropertyItem[] newItems = new PropertyItem[items.Length]; for (int i = 0; i < newItems.Length; ++i) { newItems[i] = PdnGraphics.ClonePropertyItem(items[i]); } info = new ExifInfo(names, newItems); } else { string[] names2 = new string[info.names.Length + names.Length]; PropertyItem[] items2 = new PropertyItem[info.items.Length + items.Length]; info.names.CopyTo(names2, 0); names.CopyTo(names2, info.names.Length); info.items.CopyTo(items2, 0); for (int i = 0; i < items.Length; ++i) { items2[i + info.items.Length] = PdnGraphics.ClonePropertyItem(items[i]); } info = new ExifInfo(names2, items2); } this.exifIdToExifInfo[idObj] = info; --suppressChangeEvents; OnChanged(); }