به جای این خط ها:op.ShowDialog();
if (op.FileName!="")
{
Image newImg = Image.FromFile(op.FileName);
pbxPictureAx.Image = newImg;
}
از این خط کد ها استفاده کن:
if (op.ShowDialog() == DialogResult.OK)
{
Image newImg = Image.FromFile(op.FileName);
pbxPictureAx.Image = newImg;
}
و به جای این خط:
PictureAx = File.ReadAllBytes(op.FileName);
این خط کد هارو جایگذاری کن:
if (pbxPictureAx.Image != null)
{
Bitmap oBitmap = new Bitmap(pbxPictureAx.Image);
System.IO.MemoryStream oMemory = new System.IO.MemoryStream();
oBitmap.Save(oMemory, System.Drawing.Imaging.ImageFormat.Jpeg);
PictureAx = oMemory.GetBuffer();
}
else
{
PictureAx = null;
}