有一张原图破存在了,现在已知4个点的坐标,就可以确定一个图片的大小,现在要在原图上进行裁剪出相应大小的一张图片
请问有哪位做过.....
另如果有和CSDN中上传头像一样的功能的,希望传一份给我,万分感谢!
email:[email protected]

解决方案 »

  1.   

                    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只是另存为像素比较低的图片罢了
      

  2.   

    Bitmap bmp = new Bitmap(80/*宽度*/, 80/*高度*/);using (Graphics canvas = Graphics.FromImage(bmp))
    {
        bmp.MakeTransparent(Color.White); //自定义透明色(可选)
        canvas.DrawImage(Image.FromFile(@"原图路径"), 0/*X*/, 0/*Y*/, bmp.Width, bmp.Height);
        canvas.Save();
        bmp.Save(@"目标路径");
    }bmp.Dispose();
      

  3.   

    -_-!!! 手工写就是慢, 刚才只有1.楼, 记得 using System.Drawing;
      

  4.   

    //已知的4个点已标明, 请自行更改...Bitmap bmp = new Bitmap(80/*宽度*/, 80/*高度*/);using (Graphics canvas = Graphics.FromImage(bmp))
    {
        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();
      

  5.   

    //已知的4个点已标明, 请自行更改...Bitmap bmp = new Bitmap(80/*宽度*/, 80/*高度*/);using (Graphics canvas = Graphics.FromImage(bmp))
    {
        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),那应该在你的代码基本怎么修改
      

  6.   

    知道了两个点,求宽度和高度就不是难题了public Bitmap KiCut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight)
            {
                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;
                }
            }
      

  7.   

    Bitmap bmp = new Bitmap(x2 - x1/*宽度*/, y2 - y1/*高度*/); //前提: (2) >= (1)
      

  8.   

    canvas.DrawImage(Image.FromFile(@"原图路径"), new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(x1/*X*/, y1/*Y*/, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
      

  9.   

    请你标出当前坐标(x1,y1)(x2,y2)的实际值...