달력

12025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
반응형

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace App3CircularCrop
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            using(OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {                   
                    using (FileStream bmpSteam = new FileStream(openFileDialog.FileName, FileMode.Open))
                    {
                        Bitmap bmp = (Bitmap)Bitmap.FromStream(bmpSteam);
                        this.pictureBox1.Image = bmp;
                    }                    
                    this.pictureBox2.Image = MakeCircularCrop();
                }
            }
            
        }
 
        private Image MakeCircularCrop()
        {
            Bitmap bitmap = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            Graphics g = Graphics.FromImage(bitmap);
            
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(00this.pictureBox1.Width, this.pictureBox1.Height);
            Region region = new Region(path);
            g.SetClip(region, CombineMode.Replace);
            Bitmap bmp = (Bitmap)this.pictureBox1.Image;
            g.DrawImage(bmp, new Rectangle(00this.pictureBox1.Width, this.pictureBox1.Height)
                           , new Rectangle(00this.pictureBox2.Width, this.pictureBox2.Height)
                           , GraphicsUnit.Pixel);
 
            return bitmap;
        }
    }
}
cs

실행


참조 : http://codevlog.com/crop-image-in-star-shape-using-c/396

'프로그래밍 > C#' 카테고리의 다른 글

[C#]Image에 흰색 지우기  (0) 2018.07.22
[C#]텍스트 읽어들이기  (0) 2018.07.17
[C#] 유닉스시간 <> 윈도우시간 변환 함수  (0) 2018.06.27
[C#] 텍스트를 픽쳐박스로...  (0) 2018.06.23
[C#]투명한 버튼  (0) 2018.06.16
Posted by 유령회사
|