PHOTOSHOP做的事情呀,关注,帮你UP

解决方案 »

  1.   

    用这段代码:
    System.Drawing.Image myImage = System.Drawing.Image.FromFile("c:\\222.jpg");
    System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(myImage);
    graphics.DrawString("我写的文字", new Font("宋体", 12), new SolidBrush(Color.Red), new Point(10, 10));
    graphics.DrawImage(myImage, 0F, 0F);
    myImage.Save("c:\\222-1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    graphics.Dispose();
      

  2.   

    数据库的话也不难,int ImgID = 1; //能过图片记录ID来取相应的图片数据
    string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection conn = new SqlConnection(connStr);
    string sql = "select * from t_imgs where id = @ImgID";
    SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.Parameters.Add("@ImgID", SqlDbType.Int).Value = ImgID;
    conn.Open();
    SqlDataReader read = cmd.ExecuteReader();
    read.Read();
    byte[] bytes = (byte[])read["imgData"];
    read.Close();
    conn.Close();
    //把byte[]写到流中
    MemoryStream stream = new MemoryStream();
    byte[] bytes = new Byte[1];
    stream.Write(bytes, 0, bytes.Length);
    //从流中实例化图片对象
    System.Drawing.Image myImage = System.Drawing.Image.FromStream(stream);
    System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(myImage);
    //写字
    graphics.DrawString("我写的文字", new Font("宋体", 12), new SolidBrush(Color.Red), new Point(10, 10));
    //重新写一下图片
    graphics.DrawImage(myImage, 0F, 0F);
    //保存为jpg格式
    myImage.Save("c:\\222-1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    //释放对象
    graphics.Dispose();
    stream.Close();
      

  3.   

    MemoryStream stream = new MemoryStream();
    byte[] bytes = new Byte[1];   //这句多了写了,删掉它
    stream.Write(bytes, 0, bytes.Length);