نوشته شده توسط
saeed-71
سلام.
چجوری اول عکس رو تغییر سایز بدیم بعد تو دیتابیس ذخیره کنیم؟
این کد اپلود عکس منه
image = "~/" + img_upload.FileName
});
if (img_upload.HasFile)
img_upload.SaveAs(Request.PhysicalApplicationPath + img_upload.FileName);
#region Propersties
private int _imgwidth
{
get
{
return 105;
}
}
private int _imgHieght
{
get
{
return 177;
}
}
#endregion
#region Public Function
public Bitmap ResizeBitMap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage((Image)result))
g.DrawImage(b, 0, 0, nWidth, nHeight);
return result;
}
#endregion
private Image picimage = Properties.Resources.avatar_3021;
private void button2_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog fd = new OpenFileDialog();
fd.Filter = "(*.JPG) تصاویر|*.jpg|" +
"(*.GIF) تصاویر|*.Gif" +
"(*.PNG) تصاویر|*.PNG" +
"" + "(*.*) تمام تصاویر|*.*";
fd.Title = "انتخاب تصویر";
fd.ShowDialog();
float imgWidth = System.Drawing.Image.FromFile(fd.FileName).Physica lDimension.Width;
float imgHeight = System.Drawing.Image.FromFile(fd.FileName).Physica lDimension.Height;
picimage = System.Drawing.Image.FromFile(fd.FileName);
if (imgWidth > _imgwidth || imgHeight > _imgwidth)
{
string strMessage = "تصویر انتخابی شما نباید بزرگتر از {1}*{0} پیکسل باشد" + "\n" +
"آیا تمایل به تغییر اندازه عکس دارید ؟";
if (MessageBox.Show(string.Format(strMessage, _imgwidth, _imgHieght), "پیام سیستم", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
picimage = ResizeBitMap((Bitmap)picimage, _imgwidth, _imgHieght);
Pic1.Image = picimage;
}
else
{
picimage = Properties.Resources.avatar_3021;
Pic1.Image = picimage;
}
}
else
{
Pic1.Image = picimage;
}
}
catch { }
}