zoukankan      html  css  js  c++  java
  • ios-绘制-小知识点(裁减)

    -(void)drawRect:(CGRect)rect{
          CGContextRef ctx=UIGraphicsGetCurrentContext();
          CGContextBeginPath(ctx);
          CGContextAddRect(ctx, CGRectMake(100, 100, 100, 100));
          CGContextClip(ctx);//裁减,相对的CGContextClearRect是只留下矩形外面的
          CGContextBeginPath(ctx);
          CGContextAddRect(ctx, CGRectMake(0, 0, rect.size.width,   rect.size.height));
          [[UIColor brownColor]setFill];
          CGContextFillPath(ctx);
    }
    //绘制路径   
    CGMutablePathRef path=  CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 20, 20);
        CFRelease(path);

    //
    CGContextAddPath(ctx, path1);
    
    
    #pragma mark --截图
    -(void)jitu{
        //切换到图片上下问
        UIGraphicsBeginImageContext(self.frame.size);
        //将view绘制到图形上下文中
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];
        //将截屏保存到相册
        UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
        
        UIImageWriteToSavedPhotosAlbum(newImage,self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    
    }
    
    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
     {
             if (error) {
    
                 NSLog(@"保存失败,请检查是否拥有相关的权限");
                 }else
                     {
                         NSLog(@"保存成功!");
                         }
         }
    //绘制图片  
     UIGraphicsBeginImageContextWithOptions( CGSizeMake(200, 200), NO, 0);
                 //1.获取bitmap上下文
                 CGContextRef ctx = UIGraphicsGetCurrentContext();
                 //2.绘图(画一个圆)
                 CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, 100, 100));
                 //3.渲染
                 CGContextStrokePath(ctx);
                 //4.获取生成的图片
                 UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
                 //5.显示生成的图片到imageview
    //             self.iv.image=image;
                 //6.保存绘制好的图片到文件中
                 //先将图片转换为二进制数据,然后再将图片写到文件中
             //    UIImageJPEGRepresentation(image, 1); //第二个参数为保存的图片的效果
                 NSData *data=UIImagePNGRepresentation(image);
                 [data writeToFile:@"/Users/liyang/Library/Developer/abc.png" atomically:YES];

  • 相关阅读:
    关于Visual Studio中的TraceDebugging文件夹
    没有App打得开发证书, 收不到推送
    转:ios应用崩溃日志揭秘
    转 iOS:NSAttributedString
    [UIDevice currentDevice].model
    转: Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
    NSTimer 增加引用计数, 导致内存泄露,
    matplotlib基础(2)
    matplotlib基础
    《python自然语言处理》(1)
  • 原文地址:https://www.cnblogs.com/liyang31tg/p/4280435.html
Copyright © 2011-2022 走看看