我需要从数据库中提取一个图片文件 
然后转换成BMP的格式 
在IO流中实现 
完了后 告诉程序4个点的坐标 比如P1,P2,P3,P4 
让程序截取出这个规格的图片 
再存储到数据库中(另个表) 
我知道原理但是不会写 谁给点参考或者写个给我对照下 劳驾!!
谁能帮我看看下面一段是什么意思
              Rectangle roi = new Rectangle(left, top, Width, Height);
            using(Bitmap bmp = new Bitmap(roi.Width,roi.Height))
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.CopyFromScreen(this);
            }           MemoryStream   ms   =   new   MemoryStream();   
           bmp.Save(   ms,   ImageFormat.Jpeg   );   
           ms.Flush();  
           byte[]   picbyte=   ms.GetBuffer();   
           ms.Close();

解决方案 »

  1.   

    1:从数据库读取图片
    byte[] bPhoto =ds.Table[0].Row[行][列];
    System.IO.MemoryStream ms = new MemoryStream(bPhoto);
    System.Drawing.Bitmap bmp = new Bitmap(ms);
    2截取的话
    [DllImport("gdi32.dll")]
    private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwrop);
    private void GetPhoto
    {
    Rectangle rForm = new Rectangle();
    rFrom = this.Bounds;
    Graphics g1 = this.CreateGraphics();
    Image Photo = new Bitmap(p2-p1,p4-p3,g1);
    Graphics g2 = Graphics.FromImage(Photo);
    IntPtr iHandle =g1.GetHdc();
    IntPtr iSrc =g2.GetHdc();
    BitBlt(iSrc, 2, 0, rForm.Width, rForm.Height, ihandle, 0, 0, 13369376)
    g1.ReleaseHdc(ihandle);
    g2.ReleaseHdc(iSrc);
     Photo.Save(@"c:\Kevin.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    这样的话可以截取到图片
    3:保存到数据库
    System.IO.FileStream fs = new System.IO.FileStream(@"c:\Kevin.jpg", System.IO.FileMode.Open,System.IO.FileAccess.Read);
    byte[] buffByte = new byte[fs.Length];
    fs.Read(buffByte,0,(int)fs.Length);
    fs.Close();
    fs = null;
    this.data.Tables["Item"].Rows[0]["ItemImage"]=buffByte ;
    }
      

  2.   

    BitBlt(iSrc, 2, 0, rForm.Width, rForm.Height, ihandle, 0, 0, 13369376) 
    改成
    BitBlt(iSrc, 2, 0, p2-p1, p4-p3, ihandle, 0, 0, 13369376) 
    p1,p2是横坐标
    p3,p4是纵坐标
      

  3.   

    忘了说了我 只会点C#  用的是.NET
    不过好像能看懂点 就是有些看不明白
      

  4.   

    这个就是c#的啊
    [[DllImport("gdi32.dll")] ]这个是导入非托管代码
      

  5.   

     
    Rectangle roi = new Rectangle(left, top, Width, Height);  
    using(Bitmap bmp = new Bitmap(roi.Width,roi.Height)) 
    using (Graphics g = Graphics.FromImage(bmp)) 

        g.CopyFromScreen(this); 

    MemoryStream  ms  =  new  MemoryStream();  
    bmp.Save(  ms,  ImageFormat.Jpeg  );//把BMP中的流用jpeg格式保存到ms流中
    ms.Flush();
    byte[]  picbyte=  ms.GetBuffer();
    ms.Close();
      

  6.   

    IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwrop
    Graphics g1 = this.CreateGraphics(); 
    Image Photo = new Bitmap(p2-p1,p4-p3,g1); 
    Graphics g2 = Graphics.FromImage(Photo); 
    IntPtr iHandle =g1.GetHdc(); 
    IntPtr iSrc =g2.GetHdc(); 
    BitBlt(iSrc, 2, 0, rForm.Width, rForm.Height, ihandle, 0, 0, 13369376) 
    g1.ReleaseHdc(ihandle); 
    g2.ReleaseHdc(iSrc); 
    Photo.Save(@"c:\Kevin.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
    这样的话可以截取到图片 
    3:保存到数据库 
    System.IO.FileStream fs = new System.IO.FileStream(@"c:\Kevin.jpg", System.IO.FileMode.Open,System.IO.FileAccess.Read); 
    byte[] buffByte = new byte[fs.Length]; 
    fs.Read(buffByte,0,(int)fs.Length); 
    fs.Close(); 
    fs = null; 
    this.data.Tables["Item"].Rows[0]["ItemImage"]=buffByte ; 
    }
    这些都看不懂 我太菜了5555555
      

  7.   

    //导入非托管代码
    [DllImport("gdi32.dll")] 
    //定义非托管方法
    private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwrop); 
    //自定义的截图方法
    private void GetPhoto 

    //定义一个区域
    Rectangle rForm = new Rectangle(); 
    //指定为当前的区域
    rFrom = this.Bounds; 
    //一个Graphics对象
    Graphics g1 = this.CreateGraphics(); 
    //定义一个图对象
    Image Photo = new Bitmap(p2-p1,p4-p3,g1);
    //定义一个从Photo对象来的Graphics 
    Graphics g2 = Graphics.FromImage(Photo); 
    //得到窗体Graphics的句柄
    IntPtr iHandle =g1.GetHdc();
    //得到图片Graphics的句柄 
    IntPtr iSrc =g2.GetHdc(); 
    //调用非托管方法
    BitBlt(iSrc, 2, 0, rForm.Width, rForm.Height, ihandle, 0, 0, 13369376)
    //释放句柄 
    g1.ReleaseHdc(ihandle); 
    g2.ReleaseHdc(iSrc); 
    //保存图片
    Photo.Save(@"c:\Kevin.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
    这样的话可以截取到图片 
    3:保存到数据库 
    //通过文件流读取指定路径下的图片
    System.IO.FileStream fs = new System.IO.FileStream(@"c:\Kevin.jpg", System.IO.FileMode.Open,System.IO.FileAccess.Read); 
    byte[] buffByte = new byte[fs.Length];
    //把图片读取到字节数组中 
    fs.Read(buffByte,0,(int)fs.Length); 
    fs.Close(); 
    fs = null; 
    //把图片字节放到DataSet中,用于保存到数据库的
    this.data.Tables["Item"].Rows[0]["ItemImage"]=buffByte ;