Esempio n. 1
0
 private void pictureBox1_MouseWheel(object sender, MouseEventArgs e) // biến a dùng để lưu giá trị zoom
 {
     if (e.Delta > 0 && a == 200)
     {
         return;
     }
     else
     {
         if (e.Delta > 0 && a >= 5 && a < 200)
         {
             a += 5;
         }
     }
     if (e.Delta < 0 && a == 5)
     {
         return;
     }
     else
     {
         if (e.Delta < 0 && a > 5 && a <= 200)
         {
             a -= 5;
         }
     }
     if (pb_image.Image != null)
     {
         pb_image.Image = Su_ly.zoom(img, a); //zoom ảnh
     }
 }
Esempio n. 2
0
        private void pb_image_MouseUp(object sender, MouseEventArgs e)//Khi thả chuột trái
        {
            x2_picture = e.X;
            y2_picture = e.Y;

            #region Kéo thả ảnh

            if (crop_click == 0)
            {
                //kéo thả ảnh ở vị tri mới
                // thục chất là thay đổi vi trí của picturebox trong panel
                x                 = x2_picture - x1_picture;
                y                 = y2_picture - y1_picture;
                xloca_img         = pb_image.Location.X + x;
                yloca_img         = pb_image.Location.Y + y;
                pb_image.Location = new Point(xloca_img, yloca_img);
            }

            #endregion Kéo thả ảnh

            //Chon vùng cắt ảnh
            if (crop_click == 1)
            {
                //pb_image.Image = Su_ly.crop(cropx, cropy, Math.Abs(cropWidth), Math.Abs(cropHeight), pb_image.Image);
                cropBitmap = new Bitmap(Su_ly.crop(cropx, cropy, Math.Abs(cropWidth), Math.Abs(cropHeight), pb_image.Image));
            }
        }
Esempio n. 3
0
        private void pb_image_MouseMove(object sender, MouseEventArgs e)//di chuyển chuột
        {
            int x, y;

            lbX.Text = " x: " + e.X.ToString();  //In ra màn hình tọa độ điểm x
            lbY.Text = " y: " + e.Y.ToString();; //In ra màn hình tọa độ điểm y
            if (e.Button == MouseButtons.Left)   //kéo giữ chuột trái
            {
                if (pb_image.Image == null)
                {
                    return;
                }
                x = e.X;
                y = e.Y;
                if (e.X < 0)
                {
                    x = 0;
                }
                if (e.X > img.Width)
                {
                    x = img.Width - 1;
                }
                if (e.Y < 0)
                {
                    y = 0;
                }
                if (e.Y > img.Height)
                {
                    y = img.Height - 1;
                }

                pb_image.Refresh();
                cropWidth  = x - x1_picture;
                cropHeight = y - y1_picture;

                #region if Chọn button crop

                if (crop_click == 1)
                {
                    if (e.X < 0)
                    {
                    }
                    if (cropWidth > 0 && cropHeight > 0)//x > x1_picture && y > y1_picture
                    {
                        Su_ly.Ve_hinh_cn(pb_image, x1_picture, y1_picture, Math.Abs(cropWidth), Math.Abs(cropHeight));
                        cropx = x1_picture; cropy = y1_picture;
                    }
                    if (cropWidth < 0 && cropHeight < 0)//x < x1_picture && y < y1_picture
                    {
                        Su_ly.Ve_hinh_cn(pb_image, x, y, Math.Abs(cropWidth), Math.Abs(cropHeight));
                        cropx = x; cropy = y;
                    }

                    if (cropWidth < 0 && cropHeight > 0)//x < x1_picture && y > y1_picture
                    {
                        Su_ly.Ve_hinh_cn(pb_image, x, y1_picture, Math.Abs(cropWidth), Math.Abs(cropHeight));
                        cropx = x; cropy = y1_picture;
                    }
                    if (cropWidth > 0 && cropHeight < 0)//x > x1_picture && y < y1_picture
                    {
                        Su_ly.Ve_hinh_cn(pb_image, x1_picture, y, Math.Abs(cropWidth), Math.Abs(cropHeight));
                        cropx = x1_picture; cropy = y;
                    }
                }

                #endregion if Chọn button crop
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Button save ảnh crop
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnsave_Click(object sender, EventArgs e)
 {
     Su_ly.LuuFileAnh(cropBitmap);
 }