示例#1
0
 public virtual extern void SetRect([In, Out] ref IntPtr phdwp, NativeRect rcBrowser);
示例#2
0
 public static extern HResult DwmGetWindowAttribute(IntPtr hwnd, DwmWindowAttributes dwAttribute, out NativeRect lpRect, int size);
 internal static extern bool GetClientRect(IntPtr hwnd, ref NativeRect rect);
示例#4
0
 public virtual extern void Initialize(IntPtr hwndParent, [In] ref NativeRect prc, [In] FolderSettings pfs);
示例#5
0
        /// <summary>
        ///     Use the GDI+ blur effect on the bitmap
        /// </summary>
        /// <param name="destinationBitmap">Bitmap to apply the effect to</param>
        /// <param name="area">Rectangle to apply the blur effect to</param>
        /// <param name="radius">0-255</param>
        /// <param name="expandEdges">bool true if the edges are expanded with the radius</param>
        /// <returns>false if there is no GDI+ available or an exception occured</returns>
        public static bool ApplyBlur(Bitmap destinationBitmap, Rectangle area, int radius, bool expandEdges)
        {
            if (!IsBlurPossible(radius))
            {
                return(false);
            }
            var hBlurParams = IntPtr.Zero;
            var hEffect     = IntPtr.Zero;

            try
            {
                // Create a BlurParams struct and set the values
                var blurParams = BlurParams.Create(radius, expandEdges);

                // Allocate space in unmanaged memory
                hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams));
                // Copy the structure to the unmanaged memory
                Marshal.StructureToPtr(blurParams, hBlurParams, false);

                // Create the GDI+ BlurEffect, using the Guid
                var status = GdipCreateEffect(BlurEffectGuid, out hEffect);
                if (status != GdiPlusStatus.Ok)
                {
                    Log.Error().WriteLine("Couldn't create effect {0}: {1}", BlurEffectGuid, status);
                    return(false);
                }

                // Set the blurParams to the effect
                status = GdipSetEffectParameters(hEffect, hBlurParams, (uint)Marshal.SizeOf(blurParams));
                if (status != GdiPlusStatus.Ok)
                {
                    Log.Error().WriteLine("Couldn't set effect parameter: {0}", status);
                    return(false);
                }

                // Somewhere it said we can use destinationBitmap.GetHbitmap(), this doesn't work!!
                // Get the private nativeImage property from the Bitmap
                var hBitmap = GetNativeImage(destinationBitmap);

                // Create a RECT from the Rectangle
                NativeRect rec = area;
                // Apply the effect to the bitmap in the specified area
                status = GdipBitmapApplyEffect(hBitmap, hEffect, ref rec, false, IntPtr.Zero, 0);
                if (status == GdiPlusStatus.Ok)
                {
                    // Everything worked, return true
                    return(true);
                }

                Log.Error().WriteLine("Couldn't apply effect: {0}", status);
                return(false);
            }
            catch (Exception ex)
            {
                _isBlurEnabled = false;
                Log.Error().WriteLine(ex, "Problem using GdipBitmapApplyEffect: ");
                return(false);
            }
            finally
            {
                try
                {
                    if (hEffect != IntPtr.Zero)
                    {
                        // Delete the effect
                        var status = GdipDeleteEffect(hEffect);
                        if (status != GdiPlusStatus.Ok)
                        {
                            Log.Error().WriteLine("Couldn't delete effect: {0}", status);
                        }
                    }
                    if (hBlurParams != IntPtr.Zero)
                    {
                        // Free the memory
                        Marshal.FreeHGlobal(hBlurParams);
                    }
                }
                catch (Exception ex)
                {
                    _isBlurEnabled = false;
                    Log.Error().WriteLine(ex, "Problem cleaning up ApplyBlur: ");
                }
            }
        }
 internal static extern bool GetWindowRect(IntPtr hwnd, ref NativeRect rect);
示例#7
0
 /// <summary>
 /// Called to update the bounds and position of the preview control
 /// </summary>
 /// <param name="bounds"></param>
 protected abstract void UpdateBounds(NativeRect bounds);
示例#8
0
 private static extern GdiPlusStatus GdipBitmapApplyEffect(IntPtr bitmap, IntPtr effect, ref NativeRect rectOfInterest, [MarshalAs(UnmanagedType.Bool)] bool useAuxData, IntPtr auxData, int auxDataSize);
示例#9
0
 void IPreviewHandler.SetWindow(IntPtr hwnd, ref NativeRect rect)
 {
     _parentHwnd = hwnd;
     UpdateBounds(rect);
     SetParentHandle(_parentHwnd);
 }
示例#10
0
 void IPreviewHandler.SetRect(ref NativeRect rect)
 {
     UpdateBounds(rect);
 }
示例#11
0
 public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out NativeRect pvAttribute, int cbAttribute);
示例#12
0
        /// <summary>
        ///     This is to draw the actual container
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="renderMode"></param>
        public override void Draw(Graphics graphics, RenderMode renderMode)
        {
            if (TargetAdorner == null)
            {
                return;
            }
            graphics.SmoothingMode      = SmoothingMode.HighQuality;
            graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.PixelOffsetMode    = PixelOffsetMode.None;
            graphics.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;

            var lineColor     = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
            var fillColor     = GetFieldValueAsColor(FieldTypes.FILL_COLOR);
            var shadow        = GetFieldValueAsBool(FieldTypes.SHADOW);
            var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);

            var lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
            var rect        = new NativeRect(Left, Top, Width, Height).Normalize();

            if (Selected && renderMode == RenderMode.EDIT)
            {
                DrawSelectionBorder(graphics, rect);
            }

            var bubble = CreateBubble(lineThickness);

            var tail = CreateTail();

            //draw shadow first
            if (shadow && (lineVisible || Colors.IsVisible(fillColor)))
            {
                const int basealpha   = 100;
                var       alpha       = basealpha;
                const int steps       = 5;
                var       currentStep = lineVisible ? 1 : 0;
                using (var shadowMatrix = new Matrix())
                    using (var bubbleClone = (GraphicsPath)bubble.Clone())
                        using (var tailClone = (GraphicsPath)tail.Clone())
                        {
                            shadowMatrix.Translate(1, 1);
                            while (currentStep <= steps)
                            {
                                using (var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100)))
                                {
                                    shadowPen.Width = lineVisible ? lineThickness : 1;
                                    tailClone.Transform(shadowMatrix);
                                    graphics.DrawPath(shadowPen, tailClone);
                                    bubbleClone.Transform(shadowMatrix);
                                    graphics.DrawPath(shadowPen, bubbleClone);
                                }
                                currentStep++;
                                alpha = alpha - basealpha / steps;
                            }
                        }
            }

            var state = graphics.Save();

            // draw the tail border where the bubble is not visible
            using (var clipRegion = new Region(bubble))
            {
                graphics.SetClip(clipRegion, CombineMode.Exclude);
                using (var pen = new Pen(lineColor, lineThickness))
                {
                    graphics.DrawPath(pen, tail);
                }
            }
            graphics.Restore(state);

            if (Colors.IsVisible(fillColor))
            {
                //draw the bubbleshape
                state = graphics.Save();
                using (Brush brush = new SolidBrush(fillColor))
                {
                    graphics.FillPath(brush, bubble);
                }
                graphics.Restore(state);
            }

            if (lineVisible)
            {
                //draw the bubble border
                state = graphics.Save();
                // Draw bubble where the Tail is not visible.
                using (var clipRegion = new Region(tail))
                {
                    graphics.SetClip(clipRegion, CombineMode.Exclude);
                    using (var pen = new Pen(lineColor, lineThickness))
                    {
                        //pen.EndCap = pen.StartCap = LineCap.Round;
                        graphics.DrawPath(pen, bubble);
                    }
                }
                graphics.Restore(state);
            }

            if (Colors.IsVisible(fillColor))
            {
                // Draw the tail border
                state = graphics.Save();
                using (Brush brush = new SolidBrush(fillColor))
                {
                    graphics.FillPath(brush, tail);
                }
                graphics.Restore(state);
            }

            // cleanup the paths
            bubble.Dispose();
            tail.Dispose();

            // Draw the text
            DrawText(graphics, rect, lineThickness, lineColor, shadow, StringFormat, Text, Font);
        }
示例#13
0
        /// <summary>
        ///     Apply a color matrix by copying from the source to the destination
        /// </summary>
        /// <param name="source">Image to copy from</param>
        /// <param name="sourceRect">NativeRect to copy from</param>
        /// <param name="destRect">NativeRect to copy to</param>
        /// <param name="dest">Image to copy to</param>
        /// <param name="imageAttributes">ImageAttributes to apply</param>
        public static void ApplyImageAttributes(this Bitmap source, NativeRect sourceRect, Bitmap dest, NativeRect destRect, ImageAttributes imageAttributes)
        {
            if (sourceRect == NativeRect.Empty)
            {
                sourceRect = new NativeRect(0, 0, source.Width, source.Height);
            }
            if (dest == null)
            {
                dest = source;
            }
            if (destRect == NativeRect.Empty)
            {
                destRect = new NativeRect(0, 0, dest.Width, dest.Height);
            }
            using (var graphics = Graphics.FromImage(dest))
            {
                // Make sure we draw with the best quality!
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.CompositingMode    = CompositingMode.SourceCopy;

                graphics.DrawImage(source, destRect, sourceRect.X, sourceRect.Y, sourceRect.Width, sourceRect.Height, GraphicsUnit.Pixel, imageAttributes);
            }
        }
示例#14
0
 /// <summary>
 ///     Apply a color matrix by copying from the source to the destination
 /// </summary>
 /// <param name="source">Image to copy from</param>
 /// <param name="sourceRect">NativeRect to copy from</param>
 /// <param name="destRect">NativeRect to copy to</param>
 /// <param name="dest">Image to copy to</param>
 /// <param name="colorMatrix">ColorMatrix to apply</param>
 public static void ApplyColorMatrix(this Bitmap source, NativeRect sourceRect, Bitmap dest, NativeRect destRect, ColorMatrix colorMatrix)
 {
     using (var imageAttributes = new ImageAttributes())
     {
         imageAttributes.ClearColorMatrix();
         imageAttributes.SetColorMatrix(colorMatrix);
         source.ApplyImageAttributes(sourceRect, dest, destRect, imageAttributes);
     }
 }
示例#15
0
        /// <summary>
        ///     Private helper method for the FindAutoCropRectangle
        /// </summary>
        /// <param name="fastBitmap">IFastBitmap</param>
        /// <param name="referenceColor">color for reference</param>
        /// <param name="cropDifference">int</param>
        /// <returns>NativeRect</returns>
        private static NativeRect FindAutoCropRectangle(this IFastBitmap fastBitmap, Color referenceColor, int cropDifference)
        {
            var cropRectangle = NativeRect.Empty;
            var min           = new NativePoint(int.MaxValue, int.MaxValue);
            var max           = new NativePoint(int.MinValue, int.MinValue);

            if (cropDifference > 0)
            {
                for (var y = 0; y < fastBitmap.Height; y++)
                {
                    for (var x = 0; x < fastBitmap.Width; x++)
                    {
                        var currentColor = fastBitmap.GetColorAt(x, y);
                        var diffR        = Math.Abs(currentColor.R - referenceColor.R);
                        var diffG        = Math.Abs(currentColor.G - referenceColor.G);
                        var diffB        = Math.Abs(currentColor.B - referenceColor.B);
                        if ((diffR + diffG + diffB) / 3 <= cropDifference)
                        {
                            continue;
                        }
                        if (x < min.X)
                        {
                            min = min.ChangeX(x);
                        }
                        if (y < min.Y)
                        {
                            min = min.ChangeY(y);
                        }
                        if (x > max.X)
                        {
                            max = max.ChangeX(x);
                        }
                        if (y > max.Y)
                        {
                            max = max.ChangeY(y);
                        }
                    }
                }
            }
            else
            {
                for (var y = 0; y < fastBitmap.Height; y++)
                {
                    for (var x = 0; x < fastBitmap.Width; x++)
                    {
                        var currentColor = fastBitmap.GetColorAt(x, y);
                        if (!referenceColor.Equals(currentColor))
                        {
                            continue;
                        }
                        if (x < min.X)
                        {
                            min = min.ChangeX(x);
                        }
                        if (y < min.Y)
                        {
                            min = min.ChangeY(y);
                        }
                        if (x > max.X)
                        {
                            max = max.ChangeX(x);
                        }
                        if (y > max.Y)
                        {
                            max = max.ChangeY(y);
                        }
                    }
                }
            }

            if (!(NativePoint.Empty.Equals(min) && max.Equals(new NativePoint(fastBitmap.Width - 1, fastBitmap.Height - 1))) &&
                !(min.X == int.MaxValue || min.Y == int.MaxValue || max.X == int.MinValue || min.X == int.MinValue))
            {
                cropRectangle = new NativeRect(min.X, min.Y, max.X - min.X + 1, max.Y - min.Y + 1);
            }
            return(cropRectangle);
        }