EDN Admin
Well-known member
My application take screenshots every 30ms for exampl each screenshot is of the entire screen !
Not the Form but the whole pc screen.
The jpg files on my hard disk are 1920x1080 resolution.
When im using windows paint to edit the jpg screenshot file i see the text very sharp and clear.
When im using the magnifier glass on the jpg file i see it blurry.
The jpg file is the screenshot of the screen but its inside the pictureBox1 in Form1.
I can move the magnifier glass outside the form1 and the pictureBox1 area and it will magnifier it good. The problem is only when i move the magnifier over the pictureBox1 area !!!!!!
This is the magnifier glass Form code im using its not my code:///----------------------------------------------------------------------------
/// Class : MagnifierForm
/// Purpose : Provide simple magnifier.
/// Written by: Ogun TIGLI
/// History : 31 May 2006/Wed starting date.
/// 22 Dec 2006/Fri minor code fixes and hotsot support addition.
/// 01 Apr 2007/Sun XML serialization support added.
///
/// Notes:
/// This software is provided as-is, without any express or implied
/// warranty. In no event will the author be held liable for any damages
/// arising from the use of this software.
///
/// Permission is granted to anyone to use this software for any purpose,
/// including commercial applications, and to alter it and redistribute it
/// freely, subject to the following restrictions:
/// 1. The origin of this software must not be misrepresented;
/// you must not claim that you wrote the original software.
/// If you use this software in a product, an acknowledgment
/// in the product documentation would be appreciated.
/// 2. Altered source versions must be plainly marked as such, and
/// must not be misrepresented as being the original software.
/// 3. This notice cannot be removed, changed or altered from any source
/// code distribution.
///
/// (c) 2006-2007 Ogun TIGLI. All rights reserved.
///----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
namespace Magnifier20070401
{
public partial class MagnifierForm : Form
{
private bool _doMove;
public MagnifierForm()
{
InitializeComponent();
_doMove = true;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
TopMost = true;
Width = 150;
Height = 150;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mTimer = new Timer();
mTimer.Enabled = true;
mTimer.Interval = 20;
mTimer.Tick += new EventHandler(HandleTimer);
mScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
mStartPoint = new Point(500, 500);
mTargetPoint = new Point(500, 500);
speed = 0.35F;
zoom = 3.0F;
hidecursor = false;
hue = 30;
}
public MagnifierForm(bool MoveTheGlass, bool InTaskBar, int MagnifierWidth, int MagnifierHeight, Point MagnifierStartPoint, float SpeedFactor, float ChangeZoom, bool HideMouseCursor, float AdjustHue)
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
TopMost = true;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mTimer = new Timer();
mTimer.Enabled = true;
mTimer.Interval = 20;
mTimer.Tick += new EventHandler(HandleTimer);
mScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
_doMove = MoveTheGlass;
ShowInTaskbar = InTaskBar;
Width = MagnifierWidth;
Height = MagnifierHeight;
mStartPoint = MagnifierStartPoint;
mTargetPoint = MagnifierStartPoint;
speed = SpeedFactor;
zoom = ChangeZoom;
hidecursor = HideMouseCursor;
hue = AdjustHue;
}
protected override void OnShown(EventArgs e)
{
RepositionAndShow();
}
private delegate void RepositionAndShowDelegate();
private void RepositionAndShow()
{
if (InvokeRequired)
{
Invoke(new RepositionAndShowDelegate(RepositionAndShow));
}
else
{
Graphics g = Graphics.FromImage(mScreenImage);
g.CopyFromScreen(0, 0, 0, 0, new Size(mScreenImage.Width, mScreenImage.Height));
HSLAdjust.BitmapFunctions bf = new HSLAdjust.BitmapFunctions((Bitmap)mScreenImage);
bf.Hue(hue);
bf.Dispose();
g.Dispose();
if (hidecursor == true)
{
Cursor.Hide();
}
else
{
Cursor = Cursors.Cross;
}
Capture = true;
mCurrentPoint = Cursor.Position;
Show(); // to add here the bool of the Mouse Cursor to hide or not to hide
}
}
void HandleTimer(object sender, EventArgs e)
{
float dx = speed * (mTargetPoint.X - mCurrentPoint.X);
float dy = speed * (mTargetPoint.Y - mCurrentPoint.Y);
if (mFirstTime)
{
mFirstTime = false;
mCurrentPoint.X = mTargetPoint.X;
mCurrentPoint.Y = mTargetPoint.Y;
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
return;
}
mCurrentPoint.X += dx;
mCurrentPoint.Y += dy;
if (Math.Abs(dx) < 1 && Math.Abs(dy) < 1)
{
mTimer.Enabled = false;
}
else
{
// Update location
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
mLastMagnifierPosition = new Point((int)mCurrentPoint.X, (int)mCurrentPoint.Y);
}
Refresh();
}
protected override void OnMouseDown(MouseEventArgs e)
{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (_doMove == true)
{
mTargetPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTimer.Enabled = true;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
/*if (mConfiguration.DoubleBuffered)
{
// Do not paint background (required for double buffering)!
}
else
{
base.OnPaintBackground(e);
}*/
base.OnPaintBackground(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (mBufferImage == null)
{
mBufferImage = new Bitmap(Width, Height);
}
Graphics bufferGrf = Graphics.FromImage(mBufferImage);
Graphics g;
/*if (mConfiguration.DoubleBuffered)
{
g = bufferGrf;
}
else
{*/
g = e.Graphics;
//}
if (mScreenImage != null)
{
Rectangle dest = new Rectangle(0, 0, Width, Height);
int w = (int)(Width / zoom);//mConfiguration.ZoomFactor);
int h = (int)(Height / zoom);//mConfiguration.ZoomFactor);
int x = Left - w / 2 + Width / 2;
int y = Top - h / 2 + Height / 2;
g.DrawImage(
mScreenImage,
dest,
x, y,
w, h,
GraphicsUnit.Pixel);
}
e.Graphics.DrawImage(mBufferImage, 0, 0, Width, Height);
}
//--- Data Members ---
#region Data Members
private bool hidecursor;
private float zoom;
private float hue;
private float speed;
private Timer mTimer;
private Image mBufferImage = null;
private Image mScreenImage = null;
private Point mStartPoint;
private PointF mTargetPoint;
private PointF mCurrentPoint;
private Point mOffset;
private bool mFirstTime = true;
private static Point mLastMagnifierPosition = Cursor.Position;
#endregion
// New code \
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
Point pt = Control.MousePosition;
int eX = pt.X - this.Left;
int eY = pt.Y - this.Top;
mOffset = new Point(0, 0);
mCurrentPoint = PointToScreen(new Point(eX + mOffset.X, eY + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
this.Capture = true;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
if (_doMove)
{
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (_doMove == true)
{
_doMove = false;
}
else
{
_doMove = true;
}
}
}
}
This is a sample file im using as ascreenshot:
https://skydrive.live.com/redir?resid=EB1C71C44C3976D5!268&authkey=!AHtb87xtTOvICBw
Now in my form1 im doing this to load the screenshot file to the pictureBox1ictureBox1.Load(@"D:ffmpegtorunffmpeg-20130509-git-13cb6ed-win32-staticbinScreenshotsScreenshot000000.jpg");
And this is how im activating the magnifier glass on/offrotected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.M))
{
if (mf == null)
{
mf = new Magnifier20070401.MagnifierForm();
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
mf.Show();
this.Select();
}
else if (mf.IsDisposed)
{
mf = new Magnifier20070401.MagnifierForm();
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
mf.Show();
}
else
{
mf.Close();
mf = null;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
Now i checked it again i see now that the problem is when i move the magnifier glass over the PictureBox1 in Form1 and only when i move it over the pictureBox1 area !!! but if i move the magnifier glass on the screen somewhere outside the Form1 or over the Form1 it self i see the text and everything big in the magnifier glass area ans sharp and smooth enough.
The problem is only when i move the magnifier glass over the pictureBox1 area !!!
So maybe the problem is with my pictureBox1:
My pictureBox1 size is now: 760,283
The SizeMode is set to: StretchImage
I guess the problem is the StretchImage. But if im using other modes the image in the pictureBox1 not fit .
So what can i do to fix the problem ?
View the full article
Not the Form but the whole pc screen.
The jpg files on my hard disk are 1920x1080 resolution.
When im using windows paint to edit the jpg screenshot file i see the text very sharp and clear.
When im using the magnifier glass on the jpg file i see it blurry.
The jpg file is the screenshot of the screen but its inside the pictureBox1 in Form1.
I can move the magnifier glass outside the form1 and the pictureBox1 area and it will magnifier it good. The problem is only when i move the magnifier over the pictureBox1 area !!!!!!
This is the magnifier glass Form code im using its not my code:///----------------------------------------------------------------------------
/// Class : MagnifierForm
/// Purpose : Provide simple magnifier.
/// Written by: Ogun TIGLI
/// History : 31 May 2006/Wed starting date.
/// 22 Dec 2006/Fri minor code fixes and hotsot support addition.
/// 01 Apr 2007/Sun XML serialization support added.
///
/// Notes:
/// This software is provided as-is, without any express or implied
/// warranty. In no event will the author be held liable for any damages
/// arising from the use of this software.
///
/// Permission is granted to anyone to use this software for any purpose,
/// including commercial applications, and to alter it and redistribute it
/// freely, subject to the following restrictions:
/// 1. The origin of this software must not be misrepresented;
/// you must not claim that you wrote the original software.
/// If you use this software in a product, an acknowledgment
/// in the product documentation would be appreciated.
/// 2. Altered source versions must be plainly marked as such, and
/// must not be misrepresented as being the original software.
/// 3. This notice cannot be removed, changed or altered from any source
/// code distribution.
///
/// (c) 2006-2007 Ogun TIGLI. All rights reserved.
///----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
namespace Magnifier20070401
{
public partial class MagnifierForm : Form
{
private bool _doMove;
public MagnifierForm()
{
InitializeComponent();
_doMove = true;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
TopMost = true;
Width = 150;
Height = 150;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mTimer = new Timer();
mTimer.Enabled = true;
mTimer.Interval = 20;
mTimer.Tick += new EventHandler(HandleTimer);
mScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
mStartPoint = new Point(500, 500);
mTargetPoint = new Point(500, 500);
speed = 0.35F;
zoom = 3.0F;
hidecursor = false;
hue = 30;
}
public MagnifierForm(bool MoveTheGlass, bool InTaskBar, int MagnifierWidth, int MagnifierHeight, Point MagnifierStartPoint, float SpeedFactor, float ChangeZoom, bool HideMouseCursor, float AdjustHue)
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
TopMost = true;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mTimer = new Timer();
mTimer.Enabled = true;
mTimer.Interval = 20;
mTimer.Tick += new EventHandler(HandleTimer);
mScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
_doMove = MoveTheGlass;
ShowInTaskbar = InTaskBar;
Width = MagnifierWidth;
Height = MagnifierHeight;
mStartPoint = MagnifierStartPoint;
mTargetPoint = MagnifierStartPoint;
speed = SpeedFactor;
zoom = ChangeZoom;
hidecursor = HideMouseCursor;
hue = AdjustHue;
}
protected override void OnShown(EventArgs e)
{
RepositionAndShow();
}
private delegate void RepositionAndShowDelegate();
private void RepositionAndShow()
{
if (InvokeRequired)
{
Invoke(new RepositionAndShowDelegate(RepositionAndShow));
}
else
{
Graphics g = Graphics.FromImage(mScreenImage);
g.CopyFromScreen(0, 0, 0, 0, new Size(mScreenImage.Width, mScreenImage.Height));
HSLAdjust.BitmapFunctions bf = new HSLAdjust.BitmapFunctions((Bitmap)mScreenImage);
bf.Hue(hue);
bf.Dispose();
g.Dispose();
if (hidecursor == true)
{
Cursor.Hide();
}
else
{
Cursor = Cursors.Cross;
}
Capture = true;
mCurrentPoint = Cursor.Position;
Show(); // to add here the bool of the Mouse Cursor to hide or not to hide
}
}
void HandleTimer(object sender, EventArgs e)
{
float dx = speed * (mTargetPoint.X - mCurrentPoint.X);
float dy = speed * (mTargetPoint.Y - mCurrentPoint.Y);
if (mFirstTime)
{
mFirstTime = false;
mCurrentPoint.X = mTargetPoint.X;
mCurrentPoint.Y = mTargetPoint.Y;
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
return;
}
mCurrentPoint.X += dx;
mCurrentPoint.Y += dy;
if (Math.Abs(dx) < 1 && Math.Abs(dy) < 1)
{
mTimer.Enabled = false;
}
else
{
// Update location
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
mLastMagnifierPosition = new Point((int)mCurrentPoint.X, (int)mCurrentPoint.Y);
}
Refresh();
}
protected override void OnMouseDown(MouseEventArgs e)
{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (_doMove == true)
{
mTargetPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTimer.Enabled = true;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
/*if (mConfiguration.DoubleBuffered)
{
// Do not paint background (required for double buffering)!
}
else
{
base.OnPaintBackground(e);
}*/
base.OnPaintBackground(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (mBufferImage == null)
{
mBufferImage = new Bitmap(Width, Height);
}
Graphics bufferGrf = Graphics.FromImage(mBufferImage);
Graphics g;
/*if (mConfiguration.DoubleBuffered)
{
g = bufferGrf;
}
else
{*/
g = e.Graphics;
//}
if (mScreenImage != null)
{
Rectangle dest = new Rectangle(0, 0, Width, Height);
int w = (int)(Width / zoom);//mConfiguration.ZoomFactor);
int h = (int)(Height / zoom);//mConfiguration.ZoomFactor);
int x = Left - w / 2 + Width / 2;
int y = Top - h / 2 + Height / 2;
g.DrawImage(
mScreenImage,
dest,
x, y,
w, h,
GraphicsUnit.Pixel);
}
e.Graphics.DrawImage(mBufferImage, 0, 0, Width, Height);
}
//--- Data Members ---
#region Data Members
private bool hidecursor;
private float zoom;
private float hue;
private float speed;
private Timer mTimer;
private Image mBufferImage = null;
private Image mScreenImage = null;
private Point mStartPoint;
private PointF mTargetPoint;
private PointF mCurrentPoint;
private Point mOffset;
private bool mFirstTime = true;
private static Point mLastMagnifierPosition = Cursor.Position;
#endregion
// New code \
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
Point pt = Control.MousePosition;
int eX = pt.X - this.Left;
int eY = pt.Y - this.Top;
mOffset = new Point(0, 0);
mCurrentPoint = PointToScreen(new Point(eX + mOffset.X, eY + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
this.Capture = true;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
if (_doMove)
{
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (_doMove == true)
{
_doMove = false;
}
else
{
_doMove = true;
}
}
}
}
This is a sample file im using as ascreenshot:
https://skydrive.live.com/redir?resid=EB1C71C44C3976D5!268&authkey=!AHtb87xtTOvICBw
Now in my form1 im doing this to load the screenshot file to the pictureBox1ictureBox1.Load(@"D:ffmpegtorunffmpeg-20130509-git-13cb6ed-win32-staticbinScreenshotsScreenshot000000.jpg");
And this is how im activating the magnifier glass on/offrotected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.M))
{
if (mf == null)
{
mf = new Magnifier20070401.MagnifierForm();
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
mf.Show();
this.Select();
}
else if (mf.IsDisposed)
{
mf = new Magnifier20070401.MagnifierForm();
mf.StartPosition = FormStartPosition.Manual;
mf.Location = Control.MousePosition;
mf.Show();
}
else
{
mf.Close();
mf = null;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
Now i checked it again i see now that the problem is when i move the magnifier glass over the PictureBox1 in Form1 and only when i move it over the pictureBox1 area !!! but if i move the magnifier glass on the screen somewhere outside the Form1 or over the Form1 it self i see the text and everything big in the magnifier glass area ans sharp and smooth enough.
The problem is only when i move the magnifier glass over the pictureBox1 area !!!
So maybe the problem is with my pictureBox1:
My pictureBox1 size is now: 760,283
The SizeMode is set to: StretchImage
I guess the problem is the StretchImage. But if im using other modes the image in the pictureBox1 not fit .
So what can i do to fix the problem ?
View the full article