zoukankan      html  css  js  c++  java
  • 將某個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

  • 相关阅读:
    CG——Grab Cut
    asm2
    preinit_array
    tensorflow aot
    搭建elk
    Linux sed之正则表达式:sed替换字符串时,使用正则表达式的注意事项
    sed:在匹配模式的行首或者行尾插入字符
    logical exclusive 与 physical exclusive 的区别
    logical exclusive 与 physical exclusive 的区别
    ztSpyGlass工具介绍_focus357的博客-程序员宅基地
  • 原文地址:https://www.cnblogs.com/superchao8/p/2760530.html
Copyright © 2011-2022 走看看