我从Paint Editor Application下载资源项目。但是这个应用程序的放大/缩小功能有问题。在运行时,如果我单击 Zoom-In 按钮,drawArea 似乎也可以正常工作。图像已展开,滚动条已更改。图片尺寸:1366x768
但是,如果我尝试将此图像保存为位图文件。此位图的大小将调整为大于初始图像。
/// <summary>
/// Draw graphic objects and group selection rectangle (optionally)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DrawArea_Paint(object sender, PaintEventArgs e)
{
Matrix mx = new Matrix();
mx.Translate(-ClientSize.Width / 2f, -ClientSize.Height / 2f, MatrixOrder.Append);
mx.Rotate(_rotation, MatrixOrder.Append);
mx.Translate(ClientSize.Width / 2f + _panX, ClientSize.Height / 2f + _panY, MatrixOrder.Append);
mx.Scale(_zoom, _zoom, MatrixOrder.Append);
e.Graphics.Transform = mx;
////Draw image here
}
这些用于导出到图像的代码
public void ExportToFile(string filePath, ImageFormat imageFormat)
{
using (Bitmap b = new Bitmap(_drawArea.Width, _drawArea.Height))
{
using (Graphics g = Graphics.FromImage(b))
{
g.Clear(Color.White);
_drawArea.DeselectAll();
_drawArea.TheLayers.Draw(g);
b.Save(filePath, imageFormat);
}
}
}