/// <summary>
/// 缩放矩形框
/// </summary>
/// <param name="pImage">原图像</param>
/// <param name="pRate">比例</param>
/// <param name="pRectangle">矩形框</param>
private Bitmap ResizeRectangle(Bitmap pImage, float pRate, RectangleF pRectangle)
{
Bitmap newImage = null;
Graphics g = null;
Pen pen = null;
try
{
newImage = new Bitmap(pImage);
g = Graphics.FromImage(newImage);
pen = new Pen(Color.Blue, 1);
float x1 = pRectangle.X,
x2 = pRectangle.X + pRectangle.Width,
y1 = pRectangle.Y,
y2 = pRectangle.Y + pRectangle.Height,
r = pRate,
x3, x4, y3, y4;
x3 = ((r + 1) * x1 + (1 - r) * x2) / 2;
x4 = ((r + 1) * x2 + (1 - r) * x1) / 2;
y3 = ((r + 1) * y1 + (1 - r) * y2) / 2;
y4 = ((r + 1) * y2 + (1 - r) * y1) / 2;
g.DrawLine(pen, x3, y3, x4, y3);
g.DrawLine(pen, x3, y3, x3, y4);
g.DrawLine(pen, x3, y4, x4, y4);
g.DrawLine(pen, x4, y3, x4, y4);
}
catch
{ }
finally
{
if (g != null)
g.Dispose();
if (pen != null)
pen.Dispose();
GC.Collect();
}
return newImage;
}
缩放矩形框
最新推荐文章于 2024-07-16 17:14:19 发布