Dim CurImage As Image = New Bitmap(DrawRectangle.Width, DrawRectangle.Height) Dim g As Graphics = Graphics.FromImage(CurImage) Dim FromRectangle As Rectangle Dim ToRectangle As Rectangle '=========================================== FromRectangle = New Rectangle(DrawRectangle.X, DrawRectangle.Y, DrawRectangle.Width, DrawRectangle.Height) ToRectangle = New Rectangle(0, 0, DrawRectangle.Width, DrawRectangle.Height) g.Clear(Color.White) 'PicBox.Image, ToRectangle, FromRectangle '分别是:截取可能和目标图形不是一样大 '原有图形,目标图形的区域<就是在你设定的图形里面的位置>,原有图形的区域 g.DrawImage(PicBox.Image, ToRectangle, FromRectangle, GraphicsUnit.Pixel)这是我截图部分的代码——没必要弄什么点阵的,CSDN只是另存为像素比较低的图片罢了
Dim g As Graphics = Graphics.FromImage(CurImage)
Dim FromRectangle As Rectangle
Dim ToRectangle As Rectangle
'===========================================
FromRectangle = New Rectangle(DrawRectangle.X, DrawRectangle.Y, DrawRectangle.Width, DrawRectangle.Height)
ToRectangle = New Rectangle(0, 0, DrawRectangle.Width, DrawRectangle.Height)
g.Clear(Color.White)
'PicBox.Image, ToRectangle, FromRectangle
'分别是:截取可能和目标图形不是一样大
'原有图形,目标图形的区域<就是在你设定的图形里面的位置>,原有图形的区域
g.DrawImage(PicBox.Image, ToRectangle, FromRectangle, GraphicsUnit.Pixel)这是我截图部分的代码——没必要弄什么点阵的,CSDN只是另存为像素比较低的图片罢了
{
bmp.MakeTransparent(Color.White); //自定义透明色(可选)
canvas.DrawImage(Image.FromFile(@"原图路径"), 0/*X*/, 0/*Y*/, bmp.Width, bmp.Height);
canvas.Save();
bmp.Save(@"目标路径");
}bmp.Dispose();
{
bmp.MakeTransparent(Color.White); //自定义透明色(可选)
canvas.DrawImage(Image.FromFile(@"原图路径"), new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0/*X*/, 0/*Y*/, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
canvas.Save();
bmp.Save(@"目标路径"); //或者直接使用, 例如: PicBox.Image = bmp;
}bmp.Dispose();
{
bmp.MakeTransparent(Color.White); //自定义透明色(可选)
canvas.DrawImage(Image.FromFile(@"原图路径"), new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0/*X*/, 0/*Y*/, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
canvas.Save();
bmp.Save(@"目标路径"); //或者直接使用, 例如: PicBox.Image = bmp;
}bmp.Dispose();你好,那个GDI绘图的,我现在可以得到两个坐标(x1,y1)(x2,y2),那应该在你的代码基本怎么修改
{
if (b == null)
{
return null;
} int w = b.Width;
int h = b.Height; if (StartX >= w || StartY >= h)
{
return null;
} if (StartX + iWidth > w)
{
iWidth = w - StartX;
} if (StartY + iHeight > h)
{
iHeight = h - StartY;
} try
{
Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmpOut);
g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
g.Dispose(); return bmpOut;
}
catch
{
return null;
}
}