PDA

View Full Version : سوال: مشکل در تغییر اندازه تصویر قبل از ذخیره در بانک اطلاعاتی



پیام حیاتی
دوشنبه 25 اسفند 1393, 18:11 عصر
سلام
این کدهای ثبت اطلاعات به همراه تصویر در بانک اطلاعاتی هست،میخوام قبل از ذخیره ، ابعاد تصویر رو به اندازه های 80 در 100 تغییر بدم چطور باید این کار رو انجام بدم؟



byte[] img = null;
FileStream fs = new FileStream(imgLoc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
img = br.ReadBytes((int)fs.Length);
string sql = "insert into contact_reg (c_name , c_family , c_phone , c_mobile , c_phone_work , c_fax , c_email , c_website , c_address , c_description , c_image) values ('" + name.Text + "' , '" + family.Text + "' , '" + phone.Text + "' , '" + mobile.Text + "' , '" + phone_work.Text + "' , '" + fax.Text + "' , '" + email.Text + "' , '" + website.Text + "' , '" + address.Text + "' , '" + description.Text + "' , @img)";
if (con.State != ConnectionState.Open)
con.Open();
command = new SqlCommand(sql, con);
command.Parameters.Add(new SqlParameter("@img", img));
int x = command.ExecuteNonQuery();
con.Close();
MessageBox.Show(x.ToString() + "record(s) saved.");

moharam1370
دوشنبه 25 اسفند 1393, 18:39 عصر
سلام
من از این تابع استفاده می کنم

public Image Scc_Check(Image img2, int W, int H)
{
try
{
if (img2 != null)
{
var Rect = new Rectangle(new Point(0, 0), new Size(H, W));
var Cloned = new Bitmap(img2).Clone(Rect, img2.PixelFormat);
var Bitmap = new Bitmap(Cloned, new Size(H, W));
Cloned.Dispose();
return Bitmap;
}
return null;
}
catch
{
}
return null;
}