private void btnLayAnhNV_Click(object sender, EventArgs e) { OpenFileDialog ofdImages = new OpenFileDialog(); string fileName = ""; ofdImages.AddExtension = true; ofdImages.CheckFileExists = true; // ofdImages.Filter = "Image file (*.JPG;*.NPG;*JEPG)|*.JPG;*.NPG;*JEPG"; ofdImages.Filter = "JPEG Image|*.jpg|Windows Bitmap|*.bmp|All Files|*.*"; ofdImages.InitialDirectory = @"Desktop"; ofdImages.Multiselect = false; ofdImages.RestoreDirectory = true; ofdImages.Title = "Chọn hình cho nhân viên..."; string filePathVaiQuan = ""; if (ofdImages.ShowDialog() == DialogResult.OK) { filePathVaiQuan = ofdImages.FileName; try { pbLayAnhNV.Image = Image.FromFile(filePathVaiQuan.ToString()); MemoryStream ms = new MemoryStream(); ms = ReSizeImage.compress(pbLayAnhNV.Image); // pbLayAnhNV.Image.Save(ms,pbLayAnhNV.Image.RawFormat); destFileVaiQuan = ms.GetBuffer(); ms.Close(); } catch (Exception ex) { ex.Message.ToString(); } } }
private void btnChonAnh_Click(object sender, EventArgs e) { OpenFileDialog ofdImages = new OpenFileDialog(); string fileName = ""; ofdImages.AddExtension = true; ofdImages.CheckFileExists = true; // ofdImages.Filter = "Image file (*.JPG;*.NPG;*JEPG)|*.JPG;*.NPG;*JEPG"; ofdImages.Filter = "JPEG Image|*.jpg|Windows Bitmap|*.bmp|All Files|*.*"; ofdImages.InitialDirectory = @"C:\"; ofdImages.Multiselect = false; ofdImages.RestoreDirectory = true; ofdImages.Title = "Chọn hình cho áo cần may..."; string filePathVaiAo = ""; if (ofdImages.ShowDialog() == DialogResult.OK) { filePathVaiAo = ofdImages.FileName; int temp = filePathVaiAo.LastIndexOf(@"\"); fileName = filePathVaiAo.Substring(temp + 1); try { pbAnhDaiDien.Image = Image.FromFile(filePathVaiAo.ToString()); MemoryStream ms = new MemoryStream(); ms = ReSizeImage.compress(pbAnhDaiDien.Image); // pbAnhDaiDien.Image.Save(ms, pbAnhDaiDien.Image.RawFormat); destAnh = ms.GetBuffer(); ms.Close(); //// string sourceFile = Path.Combine(sourcePath, fileName); //destAnh = Path.Combine(targetPath, fileName); //string dich = Path.Combine(Application.StartupPath, destAnh); //File.Copy(sourcePath, dich, true); } catch (Exception ex) { ex.Message.ToString(); } } // MessageBox.Show(d }
private void btnLoadAnh_Click(object sender, EventArgs e) { OpenFileDialog ofdImages = new OpenFileDialog(); ofdImages.AddExtension = true; ofdImages.CheckFileExists = true; // ofdImages.Filter = "Image file (*.JPG;*.NPG;*JEPG)|*.JPG;*.NPG;*JEPG"; ofdImages.Filter = "JPEG Image|*.jpg|Windows Bitmap|*.bmp|All Files|*.*"; ofdImages.InitialDirectory = @"Desktop"; ofdImages.Multiselect = false; ofdImages.RestoreDirectory = true; ofdImages.Title = "Chọn hình cho áo cần may..."; string filePathVaiQuan = ""; if (ofdImages.ShowDialog() == DialogResult.OK) { filePathVaiQuan = ofdImages.FileName; try { pbAnhAoChonMua.Image = Image.FromFile(filePathVaiQuan.ToString()); // string sourceFile = Path.Combine(sourcePath, fileName); MemoryStream ms = new MemoryStream(); ms = ReSizeImage.compress(pbAnhAoChonMua.Image); // pbAnhAoChonMua.Image.Save(ms, pbAnhAoChonMua.Image.RawFormat); anhAo = ms.GetBuffer(); ms.Close(); // File.Delete(); } catch (Exception) { // ex.Message.ToString(); } } }