메뉴 바로가기

서브메뉴 바로가기

본문 바로가기

logo

C# .NET 자료실

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

 

namespace ImageToIcon

{

  public partial class ImageToIcon : Form

  {

    Stream myStream;

    public ImageToIcon()

    {

      InitializeComponent();

    }

 

// 파일을 열어서

// 썸네일 추출

    private void btnOpenImage_Click(object sender, EventArgs e)

    {

 

      if (ofdPicture.ShowDialog() == DialogResult.OK)

      {

        if ((myStream = ofdPicture.OpenFile()) != null)

        {

          Image image = Image.FromFile(ofdPicture.FileName);

          Image newImage = image.GetThumbnailImage(32, 32, null, new IntPtr());

          txtImagePath.Text = ofdPicture.FileName;

          pbImage.Image = newImage;

        }

      }

    }

 

// 썸네일을 아이콘으로 저장

    private void btnSaveAsIcon_Click(object sender, EventArgs e)

    {

      if (sfdPicture.ShowDialog() == DialogResult.OK)

      {

        String fileName = sfdPicture.FileName;

        Stream IconStream = System.IO.File.OpenWrite(fileName);

 

        Bitmap bitmap = new Bitmap(pbImage.Image);

        bitmap.SetResolution(72, 72);

        Icon icon = System.Drawing.Icon.FromHandle(bitmap.GetHicon());

        this.Icon = icon;

        icon.Save(IconStream);

      }

    }

  }

}

 

출처http://code.msdn.microsoft.com/windowsdesktop/Convert-Image-file-to-Icon-c927d9f7 

관련 문서가 검색되었습니다.
  1. [2016/09/24] XML 으로 환경설정 저장하기 ( \n,엔터값 포함, NewLine) by WhiteAT (9668)
  2. [2013/08/29] int array to string by WhiteAT (10278)
  3. [2013/08/29] byte array to Hexa String by WhiteAT (13026)
  4. [2013/03/17] C#, 16진수 TEXT => 10 진수 변환 by WhiteAT (23502)
  5. [2013/01/06] byte array to string by WhiteAT (13915)
  6. [2013/01/06] string to byte array by WhiteAT (13750)
  7. [2010/10/10] 프로그램을 트레이 아이콘으로 보내기, tray by WhiteAT (30474)
  8. [2010/09/05] EXE 파일 아이콘 읽어서 ListView에 출력하기 by WhiteAT (23910)