Bitmap sorBmp = new Bitmap(源文件路径); Rectangle rect = new Rectangle(x,y,w,h); Bitmap clipBmp = new Bitmap(w,h); Graphics gs = Graphics.FromImage(clipBmp); gs.DrawImage(SorBmp,rect); clipBmp.Save(另存文件名);
Bitmap sorBmp = new Bitmap(源文件路径); Rectangle rect = new Rectangle(x,y,w,h); Bitmap clipBmp = new Bitmap(w,h); Graphics gs = Graphics.FromImage(clipBmp); gs.DrawImage(SorBmp,rect); clipBmp.Save(另存文件名);
谢谢 Tan18(阿强)第二个问题如何解决?
谢谢 Tan18(阿强)第二个问题如何解决?
在指定位置并且按指定大小绘制指定的 Image 对象。 [Visual Basic] Overloads Public Sub DrawImage( _ ByVal image As Image, _ ByVal rect As Rectangle _ ) [C#] public void DrawImage( Image image, Rectangle rect ); [C++] public: void DrawImage( Image* image, Rectangle rect ); [JScript] public function DrawImage( image : Image, rect : Rectangle ); 参数 image 要绘制的 Image 对象。 rect Rectangle 结构,它指定所绘制图像的位置和大小。 返回值 此方法不返回值。 备注 由 image 对象表示的图像被缩放为 rect 矩形的尺寸。 示例 [Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作: 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建图像。 创建要在其中绘制图像的矩形。 将图像绘制到屏幕。 [Visual Basic, C#] 矩形的位置确定图像在屏幕上的位置,原始图像的大小和矩形的大小确定所绘制图像的缩放。 [Visual Basic] Public Sub DrawImageRect(e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New Rectangle(100, 100, 450, 150) ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect) End Sub [C#] public void DrawImageRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. Rectangle destRect = new Rectangle( 100, 100, 450, 150); // Draw image to screen. e.Graphics.DrawImage(newImage, destRect); }
这是我在MSDN上取得的,据我测试,并不是复制图像
Bitmap sorBmp = new Bitmap(源文件路径); 或者用API都行。
C#中可以使用Clone例如Rectangle rect = new Rectangle(x,y,MBM.Width,MBM.Height); Bitmap clipBmp = new Bitmap(MBM.Width,MBM.Height);clipBmp = BM.Clone(rect,System.Drawing.Imaging.PixelFormat.Format24bppRgb);clipBmp.Save("E:\\TestModelResult.bmp");
Bitmap BM = new Bitmap("E:\\Test.bmp");Rectangle rect = new Rectangle(x,y,W,H); Bitmap clipBmp = new Bitmap(W,H);clipBmp = BM.Clone(rect,System.Drawing.Imaging.PixelFormat.Format24bppRgb);clipBmp.Save("E:\\TestModelResult.bmp");
复制到剪切板Bitmap BM = new Bitmap("E:\\Test.bmp");Clipboard.SetDataObject(BM,true);从剪切板取出来暂时还不知道
Rectangle rect = new Rectangle(x,y,w,h);
Bitmap clipBmp = new Bitmap(w,h);
Graphics gs = Graphics.FromImage(clipBmp);
gs.DrawImage(SorBmp,rect);
clipBmp.Save(另存文件名);
Rectangle rect = new Rectangle(x,y,w,h);
Bitmap clipBmp = new Bitmap(w,h);
Graphics gs = Graphics.FromImage(clipBmp);
gs.DrawImage(SorBmp,rect);
clipBmp.Save(另存文件名);
[Visual Basic]
Overloads Public Sub DrawImage( _
ByVal image As Image, _
ByVal rect As Rectangle _
)
[C#]
public void DrawImage(
Image image,
Rectangle rect
);
[C++]
public: void DrawImage(
Image* image,
Rectangle rect
);
[JScript]
public function DrawImage(
image : Image,
rect : Rectangle
);
参数
image
要绘制的 Image 对象。
rect
Rectangle 结构,它指定所绘制图像的位置和大小。
返回值
此方法不返回值。
备注
由 image 对象表示的图像被缩放为 rect 矩形的尺寸。
示例
[Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。代码执行下列操作:
从示例文件夹中的 JPEG 文件 SampImag.jpg 创建图像。
创建要在其中绘制图像的矩形。
将图像绘制到屏幕。
[Visual Basic, C#] 矩形的位置确定图像在屏幕上的位置,原始图像的大小和矩形的大小确定所绘制图像的缩放。
[Visual Basic]
Public Sub DrawImageRect(e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 450, 150)
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub
[C#]
public void DrawImageRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle( 100, 100, 450, 150);
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect);
}
或者用API都行。
Bitmap clipBmp = new Bitmap(MBM.Width,MBM.Height);clipBmp = BM.Clone(rect,System.Drawing.Imaging.PixelFormat.Format24bppRgb);clipBmp.Save("E:\\TestModelResult.bmp");
Bitmap clipBmp = new Bitmap(W,H);clipBmp = BM.Clone(rect,System.Drawing.Imaging.PixelFormat.Format24bppRgb);clipBmp.Save("E:\\TestModelResult.bmp");
IDataObject iData = Clipboard.GetDataObject();取出剪切板中的图像但是不知道如何把IDataObject 转换为Bitmap
{
Bitmap CBM = (Bitmap)iData.GetData(DataFormats.Bitmap); this.pictureBoxResult.Image = CBM;
} 粘贴就是另外一回事了,我也正在搞图形,共同进步