Create ThumbnailImage

#pragma mark - Set thumbnailImage
-(UIImage*)setThumbnailFromImage:(UIImage *)image
{
    CGSize origImageSize = image.size;

    // The rectangle of the thumbnail
    CGRect newRect = CGRectMake(0, 0, 40, 40);

    // Figure out a scaling ratio to make sure we maintain the same aspect ratio
    float ratio = MAX(newRect.size.width / origImageSize.width,
                      newRect.size.height / origImageSize.height);

    // Creating a transparent bitmap context with a scaling factor
    // equal to that of the screen
    UIGraphicsBeginImageContextWithOptions(newRect.size, NO, .0);

    // Create a path that is rounded rectangle
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:5.0];

    // Make all subsequent drawing clip to this rounded rectangle.
    [path addClip];

    // Center the image in the thumbnail rectangle
    CGRect projectRect;
    projectRect.size.width = origImageSize.width * ratio;
    projectRect.size.height = origImageSize.height * ratio;
    projectRect.origin.x = (newRect.size.width - projectRect.size.width) / 2.0;
    projectRect.origin.y = (newRect.size.height - projectRect.size.height) / 2.0;

    // Draw the image on it
    [image drawInRect:projectRect];

    // Get the image from the image context, keep it as thumbnail
    UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();

    // Clean up the image context resources
    UIGraphicsEndImageContext();
    return smallImage;
}
时间: 2024-10-10 17:02:02

Create ThumbnailImage的相关文章

WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表

原文:WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表 一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目开发中图片的各种使用问题,经过总结,把一些经验分享一下.内容包括: WPF常用图像数据源ImageSource的创建: 自定义缩略图控件ThumbnailImage,支持网络图片.大图片.图片异步加载

[TypeScript] Create random integers in a given range

Learn how to create random integers using JavaScript / TypeScript. /** * Returns a random int between * @param start inclusive * @param before exclusive */ export function randomInt(start: number, before: number) { return start + Math.floor(Math.rand

redis error It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING

应用redis出现如下错误 It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING 参考stack overflow上文章 http://stackoverflow.com/questions/30895507/it-was-not-possible-to-connec

关于hibernate中提示can not create table ******

最近这两天,一直在搞hibernate,被 其中一个问题困扰了好久.在网上找了好久,一直都没有找到可行的方法,把jdk,jre,tomcat,装了拆,拆了装,可就是搞不好.实在是没有办法,又重新建了一个项目来测试,,从一点一滴开始试.所有的代码全部都手写,,,,可是问题依旧还在. 之所以一直没有找到解决办法,其实是自己的思维一直局限在一处,,,一直在想着hibernate只要把配置文件配置好,它就可以自己在数据库创建表结构,自己增删改查,相当的方便,可是自己 当时成功了,为什么这次却一而再再而三

How to Create an OCM Response file to Apply a Patch (文档 ID 966023.1)

How to Create an OCM Response file to Apply a Patch in Silent Mode - opatch silent (文档 ID 966023.1) APPLIES TO: Oracle Universal Installer - Version 10.2.0.1 to 11.2.0.4 [Release 10.2 to 11.2]Oracle Database - Enterprise Edition - Version 10.2.0.1 to

【cl】解决Fail to create the java Virtual Machine

eclipse打开,提示Fail to create the java Virtual Machine 解决方法: 1.到eclipse安装目录下,找到eclipse.ini 2.按键盘ctrl+F,复制以下字符“launcher.XXMaxPermSize”,去掉引号,查找 3.将随后出现的两个216m改成128m

使用Object.create()实现继承

一.常见继承方式 我们日常开发中常见的继承方式主要有: 1.默认模式: Child.prototype = new Parent(); 2.借用构造函数: function Child(a, b, c, d) { Parent.apply(this, arguments); } 3.借用和设置原型: function Child(a, b, c, d) { Parent.apply(this, arguments); } Child.prototype = new Parent(); 4.共享原

win10安装Anaconda3出现failed to create anacoda menue错误的解决方案

其他描述:[Anaconda Prompt找不到][开始菜单没有Anaconda Prompt][Anaconda failed to create anacoda menue][IPython找不到] 环境:windows10, Anaconda3 ( python3.6, 64-bit ) 错误:failed to create anacoda menue 解决思路: 从错误信息看是添加开始菜单的快捷方式失败,因此新建几个快捷方式即可. 解决方案: 重新安装Anaconda,报错后忽略,忽略

python pip fatal error in launcher unable to create process using

用pip安装一个包,不知道为啥,就报了这个错误:python pip fatal error in launcher unable to create process using “” 百度了一下,用下面的命令可以解决,搞定 python2 -m pip install XXX  另外,Python3 的pip我用python3 -m pip install --upgrade pip 搞定