Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn Phí
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn PhíĐăng Nhập

VỮNG TIN - TIẾP BƯỚC - THÀNH CÔNG


descriptionLưu ảnh vào database EmptyLưu ảnh vào database

more_horiz

Code:

        // Thay đổi kích cở ảnh
        public static Image resizeImage_Fix(string imageLocation, int newWidth, int maxHeight, bool onlyResizeIfWider)
        {
            Image loadedImage = Image.FromFile(imageLocation);
            Image resizedImage = loadedImage.GetThumbnailImage(newWidth, maxHeight, null, IntPtr.Zero);
            return resizedImage;
        }
        //Chuyển Image thành vector
        private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
        {
            byte[] Ret;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    imageToConvert.Save(ms, formatOfImage);
                    Ret = ms.ToArray();
                }
            }
            catch (Exception) { throw; }
            return Ret;
        }

descriptionLưu ảnh vào database EmptyRe: Lưu ảnh vào database

more_horiz

Code:

        private void btt_LuuAnh_Click(object sender, EventArgs e)
        {
            if (flag_pic)
            {
                try
                {
                    ThanhVien = Alpha.Get_Thanh_Vien(ID_Number);
                    Byte[] bytBLOBData = ConvertImageToByteArray(Img_news, ImageFormat.Jpeg);
                    ThanhVien.HINHANH = bytBLOBData;
                    Alpha.SubmitChanges();
                    frm.Load_Pic();
                    MessageBox.Show("Thay đổi Avatar thành công!", "Thay đổi Avatar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Ngắt kết nối với Server!", "Rồng Nhỏ thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }

descriptionLưu ảnh vào database EmptyRe: Lưu ảnh vào database

more_horiz

Code:

        private void btt_MoAnh_Click(object sender, EventArgs e)
        {
            DialogResult Result = openFileDialog_MoAnh.ShowDialog();
            if (Result == DialogResult.OK)
            {
                string file = openFileDialog_MoAnh.FileName;               
                Img_news = resizeImage_Fix(file, 65, 87, true);
                pictureBox_HinhAnh.Image = Img_news;
                flag_pic = true;
            }
        }

descriptionLưu ảnh vào database EmptyRe: Lưu ảnh vào database

more_horiz
privacy_tip Permissions in this forum:
Bạn không có quyền trả lời bài viết
power_settings_newLogin to reply