2013-08-02 3 views
2

안녕하세요 아직 Objective-C 초보자이며 누군가 나를 도울 수 있기를 바랍니다. 프로그래밍 방식으로 만든 것은 UIScrollView이며 내부에 이미지를 스 와이프 할 수 있습니다. 그런 다음 UIButton을 만들었습니다. 눌렀을 때 이미지 하위보기의 스크린 샷을 찍은 다음 카메라 롤에 저장합니다 (그 부분에서 코드에 추가 할 위치가 확실하지 않습니다). 이미지의 상단에 나중에 UILabels을 추가하고 저장 한 스크린 샷에도 해당 이미지를 표시하기 때문에 이미지 만이 아니라 스크린 샷이되도록하려는 이유가 있습니다. saveWallpaper 메소드에서 어떤 뷰를 사용할 지 모르겠다. 현재 솔루션이 작동하더라도. 이 구현을 시도하는 스크린 샷 코드를 얻으려면이 대답 Link을 보았습니다. 기본적으로 나는 UIButton 외의 모든 스크린 샷을 찍어 카메라 롤에 저장하고 싶습니다. 어떤 도움이나 방향을 주시면 감사하겠습니다. 또한 스크린 샷을 찍거나 특정 요소를 캡처하여 단일 이미지로 추가하는 방식을 시도 할 수도 있습니다. 고맙습니다!카메라 롤에 특정 화면의 스크린 샷 iOS

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    int PageCount = 21; 

    NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",@"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png",@"16.png",@"17.png",@"18.png",@"19.png",@"20.png",@"21.png", nil]; 
    scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    scroller.scrollEnabled=YES; 
    scroller.backgroundColor = [UIColor clearColor]; 
    scroller.pagingEnabled = YES; 
    scroller.bounces = NO; 
    [self.view addSubview:scroller]; 
    int width=scroller.frame.size.width; 
    int xPos=0; 
    for (int i=0; i<PageCount; i++) 
    { 
     UIImageView *ImgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)]; 
     [ImgView setImage:[UIImage imageNamed:[arrImageName objectAtIndex:i]]]; 
     [scroller addSubview:ImgView]; 
     scroller.contentSize = CGSizeMake(width, 0); 
     width +=scroller.frame.size.width; 
     xPos +=scroller.frame.size.width; 
    } 

    UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [saveButton addTarget:self 
        action:@selector(saveWallpaper:) 
     forControlEvents:UIControlEventTouchDown]; 
    [saveButton setImage:[UIImage imageNamed:@"save.png"] forState: UIControlStateNormal]; 
    [saveButton setImage:[UIImage imageNamed:@"savepressed.png"] forState:  UIControlStateHighlighted]; 
    saveButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width/2, 396, 96.5, 42); //Make this in the center 
    [self.view addSubview:saveButton]; 

} 

- (void)saveWallpaper:(id)sender 
{ 

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 
     UIGraphicsBeginImageContextWithOptions(scroller.bounds.size, NO, [UIScreen mainScreen].scale); 
    } 
    else 
    { 
     UIGraphicsBeginImageContext(scroller.bounds.size); 
     [scroller.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     NSData * data = UIImagePNGRepresentation(image); 
     [data writeToFile:@"foo.png" atomically:YES]; 
    } 

} 

답변

0

오히려 다음 내용에서와 같이 완전한 스크롤러 도면 뷰보다

[scroller.layer의 renderInContext : UIGraphicsGetCurrentContext()];

drawInRect 메서드를 사용하여 선택한 이미지와 텍스트를 그립니다. 참조 용으로 this 관련 게시물을 참조하십시오.