달력

52024  이전 다음

  • 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace App5ConsoleOutPut
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //http://redreans.tistory.com/58
            ProcessStartInfo cmd = new ProcessStartInfo();
            Process process = new Process();
            cmd.FileName = @"cmd";
            cmd.WindowStyle = ProcessWindowStyle.Hidden;             // cmd창이 숨겨지도록 하기
            cmd.CreateNoWindow = true;                               // cmd창을 띄우지 안도록 하기
 
            cmd.UseShellExecute = false;
            cmd.RedirectStandardOutput = true;        // cmd창에서 데이터를 가져오기
            cmd.RedirectStandardInput = true;          // cmd창으로 데이터 보내기
            cmd.RedirectStandardError = true;          // cmd창에서 오류 내용 가져오기
 
            process.EnableRaisingEvents = false;
            process.StartInfo = cmd;
            process.Start();
            process.StandardInput.Write(this.textBox1.Text + Environment.NewLine);
            // 명령어를 보낼때는 꼭 마무리를 해줘야 한다. 그래서 마지막에 NewLine가 필요하다
            process.StandardInput.Close();
 
            string result = process.StandardOutput.ReadToEnd();
            StringBuilder sb = new StringBuilder();
            sb.Append("[Result Info]" + DateTime.Now + "\r\n");
            sb.Append(result);
            sb.Append("\r\n");
 
            textBox2.Text = sb.ToString();
            process.WaitForExit();
            process.Close();
        }
    }
}
 
cs

실행



http://redreans.tistory.com/58 이분이 써놓은 코드 가져와서 해봤다.

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

[C#]GIF 프레임 단위로 보기  (0) 2018.10.01
[C#]파일 버전 알아내기  (0) 2018.09.13
[C#]Tuple 7.0부터 사용가능  (0) 2018.07.26
[C#]ImageResize  (0) 2018.07.24
[C#]Image에 흰색 지우기  (0) 2018.07.22
Posted by 유령회사
|
반응형

값 2개이상을 묶음으로 움직이게 하기 위해 클래스나 컬렉션을 만들어서 넣고 빼고
안해도 된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
 
namespace tuple
{
    class Program
    {
        // C# 7.0부터 사용가능 합니다.
        static void Main(string[] args)
        {
            var tuple = tupleTest();
            Console.WriteLine(tuple.i);
            Console.WriteLine(tuple.str);
 
            Console.Read();
        }
 
        static (int i, string str) tupleTest()
        {
            return (100"듀플 테스트");
        }
    }
}
 
cs

실행


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

[C#]파일 버전 알아내기  (0) 2018.09.13
[C#]cmd정보 명령 실행하고 결과 가져오기  (0) 2018.08.09
[C#]ImageResize  (0) 2018.07.24
[C#]Image에 흰색 지우기  (0) 2018.07.22
[C#]텍스트 읽어들이기  (0) 2018.07.17
Posted by 유령회사
|

[C#]ImageResize

프로그래밍/C# 2018. 7. 24. 22:11
반응형


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
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace ImageSize
{   
    public partial class Form1 : Form
    {
        Bitmap bitmapOri = null;
 
        public Form1()
        {
            InitializeComponent();
 
            this.label1.Text = this.trackBar1.Value + "%";
            this.pictureBox1.Image = bitmapOri = Properties.Resources._9996A8335B53615E1E;
        }
 
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            this.label1.Text = this.trackBar1.Value + "%";
            this.pictureBox1.Image = ResizeImage();
        }
 
        private Bitmap ResizeImage()
        {
            int width  = (bitmapOri.Width  * this.trackBar1.Value) / 100;
            int height = (bitmapOri.Height * this.trackBar1.Value) / 100;
 
            Rectangle rect = new Rectangle(00, width, height);
 
            Bitmap bitmap = new Bitmap(width, height);
            bitmap.SetResolution(bitmapOri.HorizontalResolution, bitmap.VerticalResolution);
 
            using (var g = Graphics.FromImage(bitmap))
            {
                g.CompositingMode = CompositingMode.SourceCopy;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
 
                using (var wrapmode = new ImageAttributes())
                {
                    wrapmode.SetWrapMode(WrapMode.TileFlipXY);
                    g.DrawImage(bitmapOri, rect, 00, bitmapOri.Width, bitmapOri.Height, GraphicsUnit.Pixel, wrapmode);
                }
            }
 
            return bitmap;
        }
    }
}
 
cs

실행

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

[C#]cmd정보 명령 실행하고 결과 가져오기  (0) 2018.08.09
[C#]Tuple 7.0부터 사용가능  (0) 2018.07.26
[C#]Image에 흰색 지우기  (0) 2018.07.22
[C#]텍스트 읽어들이기  (0) 2018.07.17
[C#]동그란 이미지 만들기  (0) 2018.07.01
Posted by 유령회사
|
반응형

사용이미지



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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace App4ImageCut
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            Bitmap bitmap = Properties.Resources.트와이스;
            Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
 
            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color pixel = bitmap.GetPixel(x, y);
 
                    if(pixel.R == 255 && pixel.G == 255 && pixel.B == 255)
                        newBitmap.SetPixel(x, y, Color.Transparent);
                    else
                        newBitmap.SetPixel(x, y, pixel);
                }
            }
 
            this.pictureBox1.Image = newBitmap;
        }
    }
}
 
cs


실행



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

[C#]Tuple 7.0부터 사용가능  (0) 2018.07.26
[C#]ImageResize  (0) 2018.07.24
[C#]텍스트 읽어들이기  (0) 2018.07.17
[C#]동그란 이미지 만들기  (0) 2018.07.01
[C#] 유닉스시간 <> 윈도우시간 변환 함수  (0) 2018.06.27
Posted by 유령회사
|
반응형


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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApp5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            // 한글은 저장시 utf-8은 잘되는데 나머진은 안되는 이유는 모르겠네요 ㅠㅠ
            string str = File.ReadAllText(@"lorem.txt"); // 한번에 텍스트를 다 읽어드림
            // File.ReadAllLines 배열단위로 넘겨줌
            this.textBox1.Text += str;
        }        
    }
}
 
cs

실행


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

[C#]ImageResize  (0) 2018.07.24
[C#]Image에 흰색 지우기  (0) 2018.07.22
[C#]동그란 이미지 만들기  (0) 2018.07.01
[C#] 유닉스시간 <> 윈도우시간 변환 함수  (0) 2018.06.27
[C#] 텍스트를 픽쳐박스로...  (0) 2018.06.23
Posted by 유령회사
|
반응형

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 유령회사
|
반응형


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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Program program = new Program();                                                               
            Console.WriteLine("유닉스 시간에서 윈도우 : " 
                        + program.ConvertFromUnixTimestamp(1417141032));
            Console.WriteLine("윈도우 시간에서 유닉스 : "
                              + program.ConvertToUnixTimestamp(DateTime.Now));
            Console.Read();
        }
      
        private DateTime ConvertFromUnixTimestamp(double timestamp)
        {
            DateTime origin = new DateTime(1970110000);
            return origin.AddSeconds(timestamp);
        }
 
        private double ConvertToUnixTimestamp(DateTime date)
        {
            DateTime origin = new DateTime(1970110000);
            TimeSpan diff = date - origin;
            return Math.Floor(diff.TotalSeconds);
        }
    }
}
 
cs


실행


출처

http://codeclimber.net.nz/archive/2007/07/10/Convert-a-Unix-timestamp-to-a-NET-DateTime/

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

[C#]텍스트 읽어들이기  (0) 2018.07.17
[C#]동그란 이미지 만들기  (0) 2018.07.01
[C#] 텍스트를 픽쳐박스로...  (0) 2018.06.23
[C#]투명한 버튼  (0) 2018.06.16
[C#]AnimateWindow  (0) 2018.06.13
Posted by 유령회사
|
반응형


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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace App2StringImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.pictureBox1.Width
                                     , this.pictureBox1.Height);
 
            using(Graphics gr = Graphics.FromImage(bitmap))
            {
                gr.Clear(this.pictureBox1.BackColor);
 
                if(textBox1.Text.Trim().Length > 0
                { 
                    using(Brush brush = new SolidBrush(this.textBox1.ForeColor))
                    {                    
                        SizeF size = gr.MeasureString(this.textBox1.Text
                                                    , this.textBox1.Font);
                        for (float y = 0; y < bitmap.Height; y += size.Height * 1.5f)
                        {
                            float x = y;
                            while(x > 0) x -= size.Width;
 
                            while (x <= bitmap.Width)
                            {
                                gr.DrawString(this.textBox1.Text
                                            , this.textBox1.Font
                                            , brush, x, y);
                                x += size.Width;
                            }
                        }
                    }
                }
                pictureBox1.Image = bitmap;
            }            
        }
    }
}
 
cs

실행


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

[C#]동그란 이미지 만들기  (0) 2018.07.01
[C#] 유닉스시간 <> 윈도우시간 변환 함수  (0) 2018.06.27
[C#]투명한 버튼  (0) 2018.06.16
[C#]AnimateWindow  (0) 2018.06.13
[C#]폼을 투명하게  (0) 2018.04.14
Posted by 유령회사
|
반응형



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
57
58
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace App1ButtonImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            SetButtonBackImage(button1);
            SetButtonBackImage(button2);
            SetButtonBackImage(button3);
            SetButtonBackImage(button4);
            SetButtonBackImage(button5);
            SetButtonBackImage(button6);            
        }
 
        private void SetButtonBackImage(Button button)
        {
            Point ptImg = new Point(00);
            ptImg = this.PointToScreen(ptImg);
 
            Point ptBtn = new Point(00);
            ptBtn = button.PointToScreen(ptBtn);
 
            int intXOffset = ptBtn.X - ptImg.X;
            int intYOffset = ptBtn.Y - ptImg.Y;
 
            Bitmap bitmap = new Bitmap(button.ClientSize.Width
                                               , button.ClientSize.Height);
            using (Graphics gr = Graphics.FromImage(bitmap))
            {
                Rectangle btn_rect = new Rectangle(00, button.ClientSize.Width
                                                      , button.ClientSize.Height);
                Rectangle src_rect = new Rectangle(intXOffset, intYOffset
                                                 , button.ClientSize.Width
                                                 , button.ClientSize.Height);
 
                gr.DrawImage(this.BackgroundImage, btn_rect, src_rect, GraphicsUnit.Pixel);
            }
 
            button.BackgroundImage = bitmap;
        }
    }
}
 
cs

몇 픽셀 정도 차이나는데 어차피 이런 코딩할일이 없으니 패스

실행



Posted by 유령회사
|
반응형

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
 
namespace AnimateWindow
{
    class WinAPI
    {
        public const int AW_ACTIVATE = 0x20000//창을 활성화 AW_HIDE와 함께 사용하지 마십시오.
        public const int AW_BLEND = 0X80000;    // 페이드 효과
        public const int AW_CENTER = 0X10// AW_HIDE 가 사용 되면 윈도우가 안쪽으로 축소 되거나 AW_HIDE 가 사용 되지 않으면 바깥 쪽으로 펼쳐지 도록 만듭니다 .
        public const int AW_HIDE = 0x10000// 창을 숨 깁니다.기본적으로 창이 표시됩니다.
        public const int AW_HOR_POSITIVE = 0X1//윈도우를 왼쪽에서 오른쪽으로 애니메이션
        public const int AW_HOR_NEGATIVE = 0X2//창을 오른쪽에서 왼쪽으로 애니메이션
        public const int AW_SLIDE = 0x40000//창을 오른쪽에서 왼쪽으로 애니메이션
        public const int AW_VER_POSITIVE = 0X4//창을 위에서 아래로 애니메이션
        public const int AW_VER_NEGATIVE = 0X8//창을 아래에서 위로 애니메이션화
 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int AnimateWindow(IntPtr hwand, int dwTime, int dwFlag);
 
        //BOOL WINAPI AnimateWindow (_In_HWND hwnd,_In_ DWORD dwTime,_In_ DWORD dwFlags);
        
        //매개 변수
        //hwnd[in]
        //유형 : HWND
        //애니메이션을 적용 할 창의 핸들.호출 스레드가이 윈도우를 소유하고 있어야합니다.
        
        //dwTime[in]
        //형식 : DWORD
        //밀리 초 단위로 애니메이션을 재생하는 데 걸리는 시간입니다.일반적으로 애니메이션은 재생할 때 200 밀리 초가 걸립니다.
 
        //dwFlags[in]
        //형식 : DWORD
        //애니메이션의 유형.이 매개 변수는 다음 값 중 하나 이상일 수 있습니다. 
        //기본적으로이 플래그는 창을 표시 할 때 적용됩니다.
        //창을 숨길 때 적용하려면 적절한 플래그와 함께 AW_HIDE 와 논리 OR 연산자를 사용하십시오.
    }
}
 
cs

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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace AnimateWindow
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;            
        }
 
        private void btnAW_ACTIVATE_Click(object sender, EventArgs e)
        {
            WinAPI.AnimateWindow(this.Handle, 2000, WinAPI.AW_CENTER | WinAPI.AW_HIDE);
            this.Close();
        }
    }
}
 
cs



실행

 

 


Posted by 유령회사
|