/// <summary>
/// Converts an image into an icon.
/// </summary>
/// <param name="img">The image that shall become an icon</param>
/// <param name="size">The width and height of the icon. Standard
/// sizes are 16x16, 32x32, 48x48, 64x64.</param>
/// <param name="keepAspectRatio">Whether the image should be squashed into a
/// square or whether whitespace should be put around it.</param>
/// <returns>An icon!!</returns>
private Icon MakeIcon(Image img, int size, bool keepAspectRatio)
{
Bitmap square = new Bitmap(size, size); // create new bitmap
Graphics g = Graphics.FromImage(square); // allow drawing to it int x, y, w, h; // dimensions for new image if (!keepAspectRatio || img.Height == img.Width)
{
// just fill the square
x = y = ; // set x and y to 0
w = h = size; // set width and height to size
}
else
{
// work out the aspect ratio
float r = (float)img.Width / (float)img.Height; // set dimensions accordingly to fit inside size^2 square
if (r > )
{ // w is bigger, so divide h by r
w = size;
h = (int)((float)size / r);
x = ; y = (size - h) / ; // center the image
}
else
{ // h is bigger, so multiply w by r
w = (int)((float)size * r);
h = size;
y = ; x = (size - w) / ; // center the image
}
} // make the image shrink nicely by using HighQualityBicubic mode
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(img, x, y, w, h); // draw image with specified dimensions
g.Flush(); // make sure all drawing operations complete before we get the icon // following line would work directly on any image, but then
// it wouldn't look as nice.
return Icon.FromHandle(square.GetHicon());
}

转:http://www.cnblogs.com/boneking/archive/2010/05/06/1728643.html

Image 转换成 Icon的更多相关文章

  1. 如何把你的图标转换成web字体

    在这篇教程中,我们将使用一个免费的Web应用程序IcoMoon将矢量图转换成Web字体,然后将生成的字体通过css应用到Web页面中. 通常我们在网站中必不可少的会使用到一些小图标.在正常尺寸下,布局 ...

  2. Android项目开发全程(四)-- 将网络返回的json字符串轻松转换成listview列表

    前面几篇博文介绍了从项目搭建到获取网络字符串,对一个项目的前期整体工作进行了详细的介绍,本篇接着上篇介绍一下怎么样优雅将网络返回的json字符串轻松转换成listview列表. 先上图,看一下效果. ...

  3. 将图标LOGO之类的图形图像转换成字体调用方法大全

    借鉴百度对此标题的评价: 使用字体图标的优势 字体图标除了图像清晰度之外,比位图还有哪些优势呢. 适用性:一个图标字体比一系列的图像(特别是在Retina屏中使用双倍大小的图像)要小.一旦图标字体加载 ...

  4. pyinstaller使用-python项目转换成exe可执行文件

    http://blog.csdn.net/pipisorry/article/details/50620122 Python不是每个人的计算机里面都有安装,当您写了一个好用的工具,需要一个standa ...

  5. JS 如何将“在线图片资源”转换成“base64”

    在实现html2canvas截图的功能时,会报下面的错误: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasEle ...

  6. data:image/png;base64 上传图像将图片转换成base64格式

    大家可能注意到了,网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJ ...

  7. 将jar文件转换成exe可执行文件[转]

    将jar文件转换成exe可执行文件: exe文件使用方便,而且还可以提高源码及资源的安全性,但同时也失去了java的初衷--跨平台性. 如果你坚持要转换成exe文件,请按以下方式进行: 利用exe4j ...

  8. python将url转换成二维码

    准备环境 python生成二维码,需要依赖包qrcode和PIL(二维码的实质就是一个url.) python3安装PIL:pip install PIL python2安装PIL:pip insta ...

  9. 如何将svg图标快速转换成字体图标?

    今天遇到一个客户需要我将页面的图标做成字体图标,想想哎可能整的麻烦,不过想想这也是对项目的一个优化 ( 1.字体图标直接用color自由控制颜色:2.整合在一起,减少http请求等     PS:平时 ...

随机推荐

  1. css 写一个向右的箭头

    经常写移动端页面时会用到向右的箭头,之前都是用图片,突然想到用css应该也能写,于是一搜还确实有 width: 7px; height: 7px; border-top: 2px solid #fff ...

  2. django 项目分析

    项目要点 一.功能制定 1.用户功能 #.登陆 #.权限组功能 2.数据展示功能 #.列表展示 #.详细信息展示 #.图标展示 3.资源管理功能 #远程管理 #对远程服务器上的进程具有 #开启 #关闭 ...

  3. vue+ElementUI——表格分页(前端实现方法)

    1.使用ElementUI中的<el-table></el-table>和 <el-pagination></el-pagination>组件来实现 2 ...

  4. css----7渐变

    linear-gradient(90deg,red 10%,yellow 20%,green 30%) <!DOCTYPE html> <html> <head> ...

  5. SQL Server - Store procedure 如何返回值

    存储过程 返回值 procedure return values : http://www.cnblogs.com/SunnyZhu/p/5542347.html return.select.outp ...

  6. Eclipse MyBatis generator 1.3.7插件的核心包(中文注释)

    一.最近刚搭建一个项目框架,使用springboot + mybatis,但是在使用Eclipse开发时发现开发mybatis的Dao.mapper.xml和entity时特别不方便,手工去写肯定是不 ...

  7. 学习Caffe(一)使用Caffe

    如何使用Caffe Caffe教程(http://robots.princeton.edu/courses/COS598/2015sp/slides/Caffe/caffe_tutorial.pdf) ...

  8. linux如何查看防火墙是否开启?删除iptables规则

    iptables是linux下的防火墙组件服务,相对于windows防火墙而言拥有更加强大的功能,此经验咗嚛以centos系统为例.关于iptables的一般常见操作,怎么来判断linux系统是否启用 ...

  9. css选择器之间的 空格和逗号

    当两个选择器之间有空格的情况下,代表的是子类选择器 .a .b{} 代表的是a类的b子类 而两个选择器之间没有空格的情况下,代表的是同时拥有两个类名的标签 <div class="a ...

  10. spss modeler出现使用错误提

    spss modeler出现使用错误提 1.对字段"compensation汇总导出"指定的类型不充分 问题: 为了分析需要,我加了一个"字段选项"--&quo ...