[ios] 截屏demo

截屏demo

实现思想。

将当前self.view renderIn 当前ImageContext 

然后绘制。

 

demo结合 基于soclia发送微博

 

截屏DEMO2 //方法2

UIGetScreenImage方法 是apple的私有方法 有概率不让上架
    UIImage *snapshot;
    CGImageRef cgScreen = UIGetScreenImage();
    if (cgScreen) {
        snapshot = [UIImage imageWithCGImage:cgScreen];
        CGImageRelease(cgScreen);
    }

    
    UIScreen *mainScreen = [UIScreen mainScreen];
    CGSize size = [mainScreen bounds].size;
    CGFloat scale = [mainScreen scale];
    CGFloat screenWidth = size.width * scale;
    CGFloat screenHeight = size.height * scale;
    CGRect rect=CGRectMake(0, 0, screenWidth, screenHeight);
    self.image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([snapshot CGImage], rect)];
    //res就是截图后的UII
 

 

 

 

需要导入

 

#import <QuartzCore/QuartzCore.h>

QuartzCore.framework

 

//
//  ViewController.m
//  LrnShareSNSDemo
//
//  Created by liu poolo on 12-10-22.
//  Copyright (c) 2012年 liu poolo. All rights reserved.
//

#import "ViewController.h"
#import <Social/Social.h>
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()
@property UIImage *shareImage;
@property NSString *shareText;
@end

@implementation ViewController
@synthesize shareImage=_shareImage;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.shareImage=[UIImage imageNamed:@"share_image.png"];
    self.shareText=@"现在较为蛋疼的是 用ios6自带的social.framework 发出来的 在微博来源会显示是ios而不是iphoneX 而且如果默认输入字数如果超过了限制  他会不显示  略坑爹的说";
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)buttonPressed:(id)sender {
   
    NSArray *activityItem=nil;
    if (self.shareImage) {
        activityItem=@[self.shareImage,self.shareText];
        //这里顺序无关,但是只能一个是image ,一个是nssting
        //如果是2个NNString的话就会导致 啥都不显示。
    }else{
        activityItem=@[self.shareText];
    }
    UIActivityViewController *aVC=[[UIActivityViewController alloc]initWithActivityItems:activityItem applicationActivities:nil];
    [self presentViewController:aVC animated:YES completion:nil];
}

- (IBAction)screenShotPressed:(id)sender {
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.shareImage=image;
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值