将位图转换为图标 [英] Convert bitmap to icon

查看:42
本文介绍了将位图转换为图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将位图转换为图标.但是存在一些错误,因为生成的文件只是空白.

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)
{
    Bitmap bmp = new Bitmap(sourceFile);  //sourceFile = openfiledialog.FileName;
    IntPtr Hicon = bmp.GetHicon();
    Icon myIcon = Icon.FromHandle(Hicon);

    SaveFileDialog sfd = new SaveFileDialog();
    sfd.Title = "Save Icon";
    sfd.Filter = "Icon|*.ico";
    sfd.ShowDialog();

    FileStream fileStream = new FileStream(sfd.FileName, FileMode.OpenOrCreate);
    myIcon.Save(fileStream);
    fileStream.Flush();
    fileStream.Close();

    MessageBox.Show("Image is converted successfully!");

    //Process.Start(sfd.FileName);
}

我已经尽了很多努力来找出问题所在,但未能成功.请告诉我问题出在哪里.

I've tried a lot to figure-out the problem but couldn't. Please tell me where the problem is.

推荐答案

此代码的唯一问题是它支持高达128x128的位图图像.

The only problem with this code is that it supports bitmap images upto 128x128.

如果位图的大小较大,它将生成一个空白的ico文件.

It yields a blank ico file if the size of bitmap is greater.

这篇关于将位图转换为图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆