Beispiel #1
0
            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));
            }
Beispiel #2
0
        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);
        }