如何将Image截取一部分?
比如一个picturebox中有个图片,我想要把它某一部分截取下来也存成图片,显示在另一个picturebox中,如何实现!谢谢!

解决方案 »

  1.   

    用bitmap新建一个brush,新建一个graphics.再用这个brush在graphics中画出你想要的部分.用这个graphics新建一个bitmap就可以了.
      

  2.   

    public void pic_zero(string sourcepath,string aimpath,int scale)
    {
    string originalFilename =sourcepath;
    //生成的高质量图片名称
    string strGoodFile =aimpath; //从文件取得图片对象
    System.Drawing.Image image = System.Drawing.Image.FromFile(originalFilename);
    int iImgWidth = image.Width;
    int iImgHeight = image.Height;
    int iScale = (iImgWidth / scale)>(iImgHeight/scale) ? (iImgWidth / scale) : (iImgHeight / scale); //取得图片大小
    System.Drawing.Size size = new Size(image.Width / iScale , image.Height / iScale);
    //新建一个bmp图片
    System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width,size.Height);
    //新建一个画板
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
    //设置高质量插值法
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    //设置高质量,低速度呈现平滑程度
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    //清空一下画布
    g.Clear(Color.Blue);
    //在指定位置画图
    g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), 
    new System.Drawing.Rectangle(0, 0, image.Width,image.Height),
    System.Drawing.GraphicsUnit.Pixel);
    //保存高清晰度的缩略图
    bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg);
    g.Dispose();
    }感觉对你应该有用,其实原理差不多的
      

  3.   

    Bitmap newbit = oldbitmap.clone(..)查一下clone方法就可以了。
      

  4.   

    public void Clone_Example(PaintEventArgs e)
    {
    // Create a Bitmap object from a file.
    Bitmap myBitmap = new Bitmap("Grapes.jpg");
    // Clone a portion of the Bitmap object.
    RectangleF cloneRect = new RectangleF(0, 0, 100, 100);
    //更改上面的值就可以截取不同的地方了
    PixelFormat format = myBitmap.PixelFormat;
    Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);
    // Draw the cloned portion of the Bitmap object.
    e.Graphics.DrawImage(cloneBitmap, 0, 0);
    }
      

  5.   

    clone的这个方法果然好用,不过当截取图片大了的话提示内存不足~~~应该很废内存吧!~(我的是384M的)。有没有办法解决???yanx8844(翔) 的方法...用graphics新建一个bitmap,这个地方建了,然后我保存了这个bitmap,为什么打开保存后的bmp文件发现根本没有图像??请赐教~
      

  6.   

    g.DrawImage(yourImage, yourNewRectangle, yourSourceImageRectangle, GraphicsUnit.Pixel);