Convert bitmap to icon

前端 未结 4 1169
闹比i
闹比i 2021-02-18 18:01

I am trying to convert bitmap into icon. But there is some error as the resultant file is just blank.

private void btnCnvrtSave_Click(object sender, EventArgs e)         


        
4条回答
  •  别跟我提以往
    2021-02-18 18:38

    This article describes how to convert a bitmap to an icon.

    http://www.go4expert.com/forums/showthread.php?t=19250

    It looks very similiar to your one:

    using (Cbitmap = new Bitmap(sourceImage.Text))
    {
        Cbitmap.MakeTransparent(Color.White);
        System.IntPtr icH = Cbitmap.GetHicon();
        Icon ico = Icon.FromHandle(icH);
    }
    using (System.IO.FileStream f = new System.IO.FileStream(destinationFldr.Text + "\\image.ico", System.IO.FileMode.OpenOrCreate))
    {
        ico.Save(f);
    }
    

    Try it out.

    EDITED: Added the using statements.

提交回复
热议问题