我有一个方法,它接受一个名为sourceBMP
,width
和height
的值,并根据这些规范调整图像大小。
result
变量是新BMP的指定尺寸。这个方法的作用是sourceBMP
,它在点0, 0
上呈现,并使用NearestNeighbor
进行插值(因为这些是正在插值的像素,NearestNeighbor
达到理想的宽度和高度是最佳选择。
private Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height) {
Bitmap result = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(result)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(sourceBMP, 0, 0, width, height);
}
return result;
}
据说 - 如何更改它,以便将此图重叠在白色背景上(所以我可以在图表上添加x和y轴标签)? 尝试自行更改参数,例如在高于0, 0
的位置指定起点(如result.Width/6
)只会使图像离开屏幕。
编辑:例如:
private Bitmap overlayBitmap(Bitmap sourceBMP, int width, int height) {
Bitmap result = new Bitmap(width + (width/3), height + (height/3));
using (Graphics g = Graphics.FromImage(result)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(sourceBMP, width / 6, height / 6, width + (width / 3), height + (height / 3));
}
return result;
}
上面的代码将图形推离屏幕而不是在尺寸内部。
答案 0 :(得分:0)
private Bitmap overlayBitmap(Bitmap sourceBMP, int width, int height) {
Bitmap result = new Bitmap(width + (width/3), height + (height/3));
using (Graphics g = Graphics.FromImage(result)) {
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(sourceBMP, width / 6, height / 6, width, height);
}
return result;
}