Screen color picker performance improvement

This commit is contained in:
Jaex 2015-01-25 02:22:46 +02:00
parent 9b90841966
commit 030bd9219c
3 changed files with 55 additions and 14 deletions

View file

@ -37,13 +37,35 @@ public class RectangleRegion : Surface
{
public AreaManager AreaManager { get; private set; }
// For screen color picker
public bool OneClickMode { get; set; }
public Point OneClickPosition { get; set; }
#region Screen color picker
public bool OneClickMode { get; set; }
private Bitmap bmpSurfaceImage;
public Point CurrentPosition { get; set; }
public Color CurrentColor
{
get
{
if (bmpSurfaceImage != null && !CurrentPosition.IsEmpty)
{
return bmpSurfaceImage.GetPixel(CurrentPosition.X, CurrentPosition.Y);
}
return Color.Empty;
}
}
#endregion Screen color picker
#region Screen ruler
// For screen ruler
public bool RulerMode { get; set; }
#endregion Screen ruler
public RectangleRegion()
{
AreaManager = new AreaManager(this);
@ -56,7 +78,7 @@ private void RectangleRegion_MouseDown(object sender, MouseEventArgs e)
{
if (OneClickMode && e.Button == MouseButtons.Left)
{
OneClickPosition = e.Location;
CurrentPosition = e.Location;
Close(SurfaceResult.Region);
}
}
@ -147,6 +169,11 @@ public override void Prepare()
});
}
}
if (OneClickMode)
{
bmpSurfaceImage = new Bitmap(SurfaceImage);
}
}
protected override void Update()
@ -238,10 +265,15 @@ protected override void Draw(Graphics g)
}
}
if (OneClickMode && Config.ShowInfo)
if (OneClickMode)
{
ImageHelpers.DrawTextWithOutline(g, GetColorPickerText(), new PointF(InputManager.MousePosition0Based.X + 5, InputManager.MousePosition0Based.Y + 5),
textFont, Color.White, Color.Black);
CurrentPosition = InputManager.MousePosition0Based;
if (Config.ShowInfo)
{
ImageHelpers.DrawTextWithOutline(g, GetColorPickerText(), new PointF(InputManager.MousePosition0Based.X + 5, InputManager.MousePosition0Based.Y + 5),
textFont, Color.White, Color.Black);
}
}
if (Config.ShowMagnifier)
@ -269,9 +301,8 @@ private string GetAreaText(Rectangle area)
private string GetColorPickerText()
{
Point mousePos = InputManager.MousePosition0Based;
Color color = ((Bitmap)SurfaceImage).GetPixel(mousePos.X, mousePos.Y);
return string.Format(Resources.RectangleRegion_GetColorPickerText, mousePos.X, mousePos.Y, color.R, color.G, color.B);
Color color = CurrentColor;
return string.Format(Resources.RectangleRegion_GetColorPickerText, CurrentPosition.X, CurrentPosition.Y, color.R, color.G, color.B);
}
private void DrawCrosshair(Graphics g)
@ -434,5 +465,15 @@ protected virtual void AddShapePath(GraphicsPath graphicsPath, Rectangle rect)
{
graphicsPath.AddRectangle(rect);
}
protected override void Dispose(bool disposing)
{
if (bmpSurfaceImage != null)
{
bmpSurfaceImage.Dispose();
}
base.Dispose(disposing);
}
}
}

View file

@ -170,5 +170,5 @@ Distance: {6:0.00} px / Angle: {7:0.00}°</value>
<data name="RectangleRegion_GetColorPickerText" xml:space="preserve">
<value>X: {0}, Y: {1}
R: {2}, G: {3}, B: {4}</value>
</data>
<comment>@Invariant</comment></data>
</root>

View file

@ -363,8 +363,8 @@ public static PointInfo SelectPointColor(SurfaceOptions surfaceOptions = null)
if (surface.Result == SurfaceResult.Region)
{
PointInfo pointInfo = new PointInfo();
pointInfo.Position = CaptureHelpers.ClientToScreen(surface.OneClickPosition);
pointInfo.Color = ((Bitmap)surface.SurfaceImage).GetPixel(surface.OneClickPosition.X, surface.OneClickPosition.Y);
pointInfo.Position = CaptureHelpers.ClientToScreen(surface.CurrentPosition);
pointInfo.Color = surface.CurrentColor;
return pointInfo;
}
}