当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.Lock方法代码示例

本文整理汇总了C#中System.Drawing.Bitmap.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.Lock方法的具体用法?C# Bitmap.Lock怎么用?C# Bitmap.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.Lock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTooltip

        public static Bitmap GetTooltip(Bitmap source, bool limitSearchArea = true)
        {
            Func<double, int> h = percent => (int)Math.Round(percent / 100.0 * source.Width);
            Func<double, int> v = percent => (int)Math.Round(percent / 100.0 * source.Height);
            Func<Color, bool> borderFunc = c => c.R < 10 && c.G < 10 && c.B < 10; // outermost tooltip 1px "black" border

            var cur = Cursor.Position;
            var projectedTooltipWidth = v(39); // 39% of screen resolution, that's pretty much how it scales

            Rectangle searchArea = new Rectangle(Point.Empty, source.Size);
            if (limitSearchArea)
            {
                // limit the area being searched by a rectangle around the mouse cursor to avoid getting incorrect tooltip (when two are visible)
                searchArea = Rectangle.FromLTRB(
                    (int)Math.Max(0, cur.X - projectedTooltipWidth * 1.2), // a little more to the left than the projected tooltip width (sometimes the tooltip is not shown directly next to the cursor)
                    0,
                    Math.Min(cur.X + projectedTooltipWidth * 3 / 4, source.Width),
                    (int)(source.Height * 0.8)
                );
            }

            var searchAreaSize = searchArea.Width * searchArea.Height;

            using (var locked = source.Lock())
            {
                var lines = GetTooltipBlackLines(locked, searchArea, projectedTooltipWidth, v);
                if (lines == null || lines.Count == 0)
                {
                    return null; // tooltip not found
                }

                var first = lines[0];
                var last = lines.Last();

                // searching for left border
                var range = Enumerable.Range(first.P1.X - v(1), v(0.5)).Reverse();
                var left = FindVerticalBorder(locked, range, first.P1.Y, v, borderFunc);

                range = Enumerable.Range(first.P2.X + v(0.5), v(0.5));
                var right = FindVerticalBorder(locked, range, first.P2.Y, v, borderFunc, false);

                if (left == null || right == null)
                {
                    return null; // tooltip not found - why here? :/
                }

                Trace.WriteLine(string.Format("Searched {0:0.00%} of pixels", locked.PixelsRead * 1f / (source.Width * source.Height)));

                var borderWidth = first.P1.X - left.P1.X; // distance between first pixel of first black line and the outer black 1px border found just above
                var ttRect = Rectangle.FromLTRB(left.P1.X, left.P1.Y, right.P1.X + 1, last.P1.Y + borderWidth);

                //g.DrawRectangle(Pens.Lime, ttRect);
                return source.Clone(ttRect, source.PixelFormat);
            }
        }
开发者ID:ipatalas,项目名称:D3Bit,代码行数:55,代码来源:Screenshot.cs

示例2: GetTooltip_LinesV2

        public Bitmap GetTooltip_LinesV2(Bitmap source, Rectangle searchArea, Graphics g)
        {
            Func<double, int> h = percent => (int)Math.Round(percent / 100.0 * source.Width);
            Func<double, int> v = percent => (int)Math.Round(percent / 100.0 * source.Height);

            Func<Color, bool> borderFunc = c => c.R < 10 && c.G < 10 && c.B < 10; // tooltip 1px border

            var searchAreaSize = searchArea.Width * searchArea.Height;
            var projectedTooltipWidth = v(39); // 39% of screen resolution

            using (var locked = source.Lock())
            {
                var lines = GetTooltipBlackLines(locked, searchArea, projectedTooltipWidth, v, g);
                if (lines == null || lines.Count == 0)
                {
                    return null; // tooltip not found
                }

                var first = lines[0];
                var last = lines.Last();

                // searching for left border
                var range = Enumerable.Range(first.P1.X - v(1), v(0.5)).Reverse();
                var left = FindVerticalBorder(locked, range, first.P1.Y, v, borderFunc);

                range = Enumerable.Range(first.P2.X + v(0.5), v(0.5));
                var right = FindVerticalBorder(locked, range, first.P2.Y, v, borderFunc, false);

                if (left == null || right == null)
                {
                    return null; // tooltip not found - why here? :/
                }

                var borderWidth = first.P1.X - left.P1.X; // distance between first pixel of first black line and the outer black 1px border found just above
                var ttRect = Rectangle.FromLTRB(left.P1.X, left.P1.Y, right.P1.X + 1, last.P1.Y + borderWidth);

                g.DrawRectangle(Pens.Lime, ttRect);

                Trace.WriteLine(string.Format("Searched {0:0.00%} of pixels", locked.PixelsRead * 1f / (source.Width * source.Height)));

                return source.Clone(ttRect, source.PixelFormat);
            }
        }
开发者ID:ipatalas,项目名称:D3Bit,代码行数:43,代码来源:frmMain.cs

示例3: GetTextBounding

 public static Rectangle GetTextBounding(Bitmap bitmap, Rectangle outerBound, Func<Color, bool> colorFunc)
 {
     using (var locked = bitmap.Lock())
     {
         return GetTextBounding(locked, outerBound, colorFunc);
     }
 }
开发者ID:ipatalas,项目名称:D3Bit,代码行数:7,代码来源:ImageUtil.cs


注:本文中的System.Drawing.Bitmap.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。