1个回答
展开全部
我在 项目 中用的
读取 缩小 显示的
string sqlstr = " SELECT FPhoto FROM T_EquEquipmentPhoto WHERE FID=" + id.ToString() ;
DataTable dt = new DataTable();
dt = GlobalValue.GlobalSQL["Master"].ExecuteDataset(CommandType.Text,sqlstr).Tables[0];
if (dt.Rows.Count <= 0)
return;
if (dt.Rows[0]["FPhoto"] == System.DBNull.Value)
{
return;
}
byte[] img = (byte[])dt.Rows[0]["FPhoto"];//
MemoryStream ms = new MemoryStream(img);//读取数据流,把数据流转换成MS
Image oldImage = Image.FromStream(ms);//
Image newimage = oldImage.GetThumbnailImage(200, 200, new Image.GetThumbnailImageAbort(istrue), IntPtr.Zero);//缩小图片
picBoxEqu.Image = newimage;// Image.FromStream(ms);//
一下 导入图片
int phtotoRecordid = (int)udw_EquEquipmentPhotoList.PrimaryData[udw_EquEquipmentPhotoList.CurrentRow, "FID"];
FileDialog fdimg;
fdimg = new System.Windows.Forms.OpenFileDialog();
fdimg.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";//"JPG 文件|*.jpg";
if (fdimg.ShowDialog() == DialogResult.OK)
{
string filename = fdimg.FileName;
FileInfo fi = new FileInfo(filename);
byte[] imgStream = new byte[fi.Length];
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
fs.Read(imgStream, 0, imgStream.Length);
char []cList=filename.ToCharArray();
for (int i = filename.Length; i > 0; i--)
{
if (((int)cList[i-1]) == 92)
{
filename = filename.Substring(i);
break;
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("update dbo.T_EquEquipmentPhoto set ");
strSql.Append("FPhoto=@FPhoto,FFileName=@FFileName");
strSql.Append(" where FID=@FID ");
SqlParameter[] parameters = {
new SqlParameter("@FID", SqlDbType.Int,4),
new SqlParameter("@FPhoto", SqlDbType.Image),
new SqlParameter("@FFileName", SqlDbType.VarChar)
};
parameters[0].Value = phtotoRecordid;
parameters[1].Value = imgStream;
parameters[2].Value = filename;
GlobalValue.GlobalSQL["Master"].ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
RemindInformation.ShowMessageOk("导入图片成功!");
读取 缩小 显示的
string sqlstr = " SELECT FPhoto FROM T_EquEquipmentPhoto WHERE FID=" + id.ToString() ;
DataTable dt = new DataTable();
dt = GlobalValue.GlobalSQL["Master"].ExecuteDataset(CommandType.Text,sqlstr).Tables[0];
if (dt.Rows.Count <= 0)
return;
if (dt.Rows[0]["FPhoto"] == System.DBNull.Value)
{
return;
}
byte[] img = (byte[])dt.Rows[0]["FPhoto"];//
MemoryStream ms = new MemoryStream(img);//读取数据流,把数据流转换成MS
Image oldImage = Image.FromStream(ms);//
Image newimage = oldImage.GetThumbnailImage(200, 200, new Image.GetThumbnailImageAbort(istrue), IntPtr.Zero);//缩小图片
picBoxEqu.Image = newimage;// Image.FromStream(ms);//
一下 导入图片
int phtotoRecordid = (int)udw_EquEquipmentPhotoList.PrimaryData[udw_EquEquipmentPhotoList.CurrentRow, "FID"];
FileDialog fdimg;
fdimg = new System.Windows.Forms.OpenFileDialog();
fdimg.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";//"JPG 文件|*.jpg";
if (fdimg.ShowDialog() == DialogResult.OK)
{
string filename = fdimg.FileName;
FileInfo fi = new FileInfo(filename);
byte[] imgStream = new byte[fi.Length];
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
fs.Read(imgStream, 0, imgStream.Length);
char []cList=filename.ToCharArray();
for (int i = filename.Length; i > 0; i--)
{
if (((int)cList[i-1]) == 92)
{
filename = filename.Substring(i);
break;
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("update dbo.T_EquEquipmentPhoto set ");
strSql.Append("FPhoto=@FPhoto,FFileName=@FFileName");
strSql.Append(" where FID=@FID ");
SqlParameter[] parameters = {
new SqlParameter("@FID", SqlDbType.Int,4),
new SqlParameter("@FPhoto", SqlDbType.Image),
new SqlParameter("@FFileName", SqlDbType.VarChar)
};
parameters[0].Value = phtotoRecordid;
parameters[1].Value = imgStream;
parameters[2].Value = filename;
GlobalValue.GlobalSQL["Master"].ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
RemindInformation.ShowMessageOk("导入图片成功!");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询