|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/**
*截图功能
*/
-(
void
)screenShot{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(640, 960), YES, 0);
//设置截屏大小
[[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = viewImage.CGImage;
CGRect rect = CGRectMake(0, 0, 641, SCREEN_HEIGHT + 300);
//这里可以设置想要截图的区域
CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];
//以下为图片保存代码
UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);
//保存图片到照片库
NSData *imageViewData = UIImagePNGRepresentation(sendImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pictureName= @
"screenShow.png"
;
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:pictureName];
[imageViewData writeToFile:savedImagePath atomically:YES];
//保存照片到沙盒目录
CGImageRelease(imageRefRect);
//从手机本地加载图片
UIImage *bgImage2 = [[UIImage alloc]initWithContentsOfFile:savedImagePath];
}
|
2.UIScrollView截屏(一屏无法显示完整)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/**
*截图
*/
- (
void
)screenShot{
UIImage* image = nil;
UIGraphicsBeginImageContext(m_scrollView.contentSize);
{
CGPoint savedContentOffset = m_scrollView.contentOffset;
CGRect savedFrame = m_scrollView.frame;
m_scrollView.contentOffset = CGPointZero;
m_scrollView.frame = CGRectMake(0, 0, m_scrollView.contentSize.width, m_scrollView.contentSize.height); [m_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
m_scrollView.contentOffset = savedContentOffset;
m_scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
if
(image != nil) {
NSLog(@
"截图成功!"
);
}
}
|
本文深入探讨了iOS开发中Swift语言的核心应用,包括基本语法、数据类型、控制结构、函数、类与继承等关键概念,同时展示了如何利用Swift进行高效、安全的iOS应用程序开发。
2228

被折叠的 条评论
为什么被折叠?



