/// <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. 【模板篇】k短路 SDOI2010 魔法猪学院

    题目传送门 吐槽时间 题目分析 代码 题目の传送门 都成了一道模板题了OvO ============================================================= ...

  2. 2019牛客暑期多校训练营(第八场)D-Distance 定期重构

    题目传送门 题意: 在一个三维空间中,给出q次操作,每次操作可以在空间中加上一个固定点,或者询问一个点,对于一个询问操作,输出距离这个点最近的固定点的曼哈顿距离. 思路: 官方题解:先假设所有询问都在 ...

  3. 使用line-height垂直居中在安卓手机上效果不好

    前端实现单行垂直居中用的最多的方法可能就是line-height了吧.该属性在pc端和ios手机上效果都很好,可到了安卓手机,有很大几率发生文字上移的现象 知乎有人分析了导致这一现象的原因,Andro ...

  4. 阿里云发布新版SaaS上云工具包,全面助力SaaS上云

    9月26日,在云栖大会SaaS加速器专场上,阿里云发布了新版的SaaS上云工具包(SaaS Launch Kit),发布了API网关的新功能,以及推出了全新升级的能力中心. SaaS上云工具包,顾名思 ...

  5. 在类中,调用这个类时,用$this->video_model是不是比每次调用这个类时D('Video')效率更高呢

    在类中,调用这个类时,用$this->video_model是不是比每次调用这个类时D('Video')效率更高呢  

  6. 使用maven搭建Hibernate

    使用maven搭建Hibernate框架(web项目) create table USERS ( ID NUMBER not null primary key, NAME ), PASSWORD ), ...

  7. 7_1.springboot2.x启动配置原理_1.创建SpringApplication对象

    环境准备 springboot2.1.9.idea2019. pom.xml 解析 几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContex ...

  8. java_Properties集合

    package propertiesTest; import java.io.FileReader; import java.io.FileWriter; import java.io.IOExcep ...

  9. Django中static文件的引入

    1. 在django project中创建 static文件夹 2.settings.py中配置要在 STATIC_URL = '/static/'  下边 STATICFILES_DIRS = [ ...

  10. UMP系统架构 RabbitMQ