下面的例子是我从数据库读取图片的
OracleConnection conn = new OracleConnection(connstring)
conn.Open()
label1.Text = "开始时间:" + DateTime.Now
string begin = "数据库连接正常,开始时间" + DateTime.Now
SetInfo("", begin)
string SQL = "select ID from bs_buylicense_attach t where t.file_size>204800 order by t.file_size asc" //rownum<100 and
string ConnString = SQL
OracleDataAdapter sda = new OracleDataAdapter(ConnString, conn)
DataTable table = new DataTable()
sda.Fill(table)
List<object>lst = ModelConvertHelper.DtCovertIList(table)
foreach (object o in lst)
{
string path = "C:\\1.png"
string lst_ID = o.ToString() //查询返回来对应的数据的ID
string filter = "select * from bs_buylicense_attach where ID='" + lst_ID + "'"
OracleCommand cmd = new OracleCommand(filter, conn)
OracleDataReader reader = cmd.ExecuteReader()
while (reader.Read())
{
if (reader["DATA"] != DBNull.Value)
{
string ID = "数据ID对应值ID" + reader["ID"].ToString()
string length = "原文件大小" + reader["FILE_SIZE"].ToString()
SetInfo(ID, length)
System.IO.MemoryStream stream = new System.IO.MemoryStream((byte[])reader["DATA"])//把照片读到MemoryStream里
Image ImageBlob = Image.FromStream(stream, true) //从数据库中读到的图片
int height = ImageBlob.Height //原来图片的高度
int width = ImageBlob.Width//原来图片的宽度
//开始进行图片的压缩
GetPicThumbnail1(ImageBlob, path, height, width, 60)
Image SaveImage = im//得到返回来压缩之后的图片
byte[] buffer = imageToByteArray(SaveImage)
string UpdateSql = "update bs_buylicense_attach set DATA =:image where ID='" + lst_ID + "'"
OracleCommand cd = new OracleCommand()
cd = new OracleCommand(UpdateSql, conn)
cd.CommandText = UpdateSql
cd.Parameters.Add("image", System.Data.OracleClient.OracleType.Blob, buffer.Length).Value = buffer
cd.ExecuteNonQuery()
FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read)
string YAsuo = Convert.ToString(file.Length)
SetInfo("压缩为:", YAsuo)
stream.Close()
stream.Dispose()
file.Dispose()
file.Close()
File.Delete(@path)
}
}
}
conn.Close()
string end = "所有数据执行完毕关闭数据库链接!" + DateTime.Now
SetInfo("", end)
SaveLog()
label2.Text = "结束时间:" + DateTime.Now
}
如果你的2010版不是官网的,建议到官网下载一个QQ2011的安装文件后安装。至于用户文件目录可以在主面板的设置--基本设置--文件记录 中设置。QQ用不了不要着急,重装新正式版可以解决很多问题。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)