Пример #1
0
        private async void pickBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Title  = "Chọn hình ảnh";
            open.Filter = "Image Files(*.jpg) | *.jpg";

            if (open.ShowDialog() == DialogResult.OK)
            {
                System.Drawing.Image img = new Bitmap(open.FileName);
                pictureBoxAccount.Image = img;
            }
            changeBtn.Enabled = false;
            MemoryStream ms = new MemoryStream();

            pictureBoxAccount.Image.Save(ms, ImageFormat.Jpeg);

            byte[] byteConvert = ms.GetBuffer();

            string output = Convert.ToBase64String(byteConvert);

            var data = new DTO.Image
            {
                Img = output
            };

            SetResponse response = await client.SetTaskAsync("Image/", data);

            DTO.Image result = response.ResultAs <DTO.Image>();
            img = result.Img;
            changeBtn.Enabled = true;
        }
Пример #2
0
        private async void uploadImg_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Title  = "Chọn hình ảnh";
            open.Filter = "Image Files(*.jpg) | *.jpg";

            if (open.ShowDialog() == DialogResult.OK)
            {
                System.Drawing.Image img = new Bitmap(open.FileName);
                pictureBoxProduct.Image = img;
            }
            addBtn.Enabled  = false;
            editBtn.Enabled = false;
            MemoryStream ms = new MemoryStream();

            pictureBoxProduct.Image.Save(ms, ImageFormat.Jpeg);

            byte[] byteConvert = ms.GetBuffer();

            string output = Convert.ToBase64String(byteConvert);

            var data = new DTO.Image
            {
                Img = output
            };

            SetResponse response = await client.SetTaskAsync("Image/", data);

            DTO.Image result = response.ResultAs <DTO.Image>();
            img             = result.Img;
            addBtn.Enabled  = true;
            editBtn.Enabled = true;
            //byte[] b = Convert.FromBase64String(result.Img);

            //MemoryStream memoryStream = new MemoryStream();
            //memoryStream.Write(b, 0, Convert.ToInt32(b.Length));

            //Bitmap bm = new Bitmap(memoryStream, false);
            //memoryStream.Dispose();
            //Picturebox.Image=bm;
        }