• 將某個UIView 轉換成圖像


    - (UIImage *)renderImageFromView:(UIView *)the_view {
    	UIGraphicsBeginImageContextWithOptions(the_view.bounds.size, the_view.opaque, 0.0);
    	CGContextRef context=UIGraphicsGetCurrentContext();
    	[the_view.layer renderInContext:context];
    	//取得影像
    	UIImage *the_image = UIGraphicsGetImageFromCurrentImageContext();
    	UIGraphicsEndImageContext();
    	return the_image;
    }


    記得要加入QuartzCore.framework,及

    #import <QuartzCore/QuartzCore.h>

    一般來說,我們會用這個指令UIGraphicsBeginImageContext(CGSize size);來指定繪圖區域的大小,但是如果需要指定是否透底色或放大縮小內容,就需要下面著指令UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);就實用來說,我比較常用 UIGraphicsBeginImageContext(CGSize size)。

    一般而言,通常為以 UIGraphicsBeginImageContext 建立繪圖區域,然後開始繪圖,完成之後取得 UIImage (使用UIGraphicsGetImageFromCurrentImageContext),最後以 UIGraphicsEndImageContext 來結束整個繪圖工作。

     注:UIGraphicsBeginImageContext(CGSize size)创建一个基于位图的上下文(context),并将其设置为当前上下文。函数功能与UIGraphicsBeginImageContextWithOptions相同,相当于该方法的opaque参数为NO,scale因子为1.0。而UIGraphicsEndImageContext()方法是移除栈顶的基于当前位图的图形上下文

    From:http://ikevin.tw/139

  • 相关阅读:
    global mapper合并多个tif影像
    arcgis 10.2 licence manager无法启动
    Error C2079 'CMFCPropertySheet::m_wndOutlookBar' uses undefined class 'CMFCOutlookBar'
    家里的技嘉B360主板win10 uefi系统安装
    vc 6.0项目转为vs 2017项目遇到 的问题
    PPT学习笔记
    git拉取分支
    将本地源码推向gitee码云
    java反编译工具使用记录
    node.js install and cecium apply
  • 原文地址:https://www.cnblogs.com/superchao8/p/2760530.html
Copyright © 2020-2023  润新知