2011-04-13 2 views
1

어떻게 든 하나의 ImageView로 인쇄 화면을 프로그래밍 방식으로 만들 수 있습니까? iPhone 이미지보기 인쇄 화면 - 이미지보기에서 새 이미지 만들기

의 내가 자동으로 조정, 다른 크기로, 중심 (AspectFit) 화면의 크기를, 큰 사진을 표시하고 검은 배경으로하고있어 가정 해 봅시다. 320x480 이미지를 사용하려면 검정색 이미지 뷰 배경을 포함하여 크기가 조정 된 이미지를 캡처하고 싶습니다.

그래서 검은 색 테두리와 함께이 이미지 뷰를 오버레이 다른 요소 (버튼, 라벨)없이 320 × 480으로 예를 들어 350x600 이미지를 변경하는 방법? ... 사전에

감사를 안드로이드에 난 그냥 화면 버퍼를 캡처하고있어하지만 아이폰 정말 그것을 어떻게 아무 생각이 없다!

+0

루 scren 내가 self.imageview.layer을 캡처하고있어 :(빈 흰색 8킬로바이트 파일에 디스크 결과 –

답변

5
UIGraphicsBeginImageContext(<specify your size here as CGRect>); 
[<yourImageView or view you want to convert in image>.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 

viewImage 출력한다. 이 같은 논리를 가질 수 있도록 검은 색 테두리를 원하는대로, 당신은 당신의 국경을 가질 수 있도록 각 측면에서 약간의 여유와 이미지 뷰의 프레임보다 커야이보기의 프레임을 기억 (검은 색으로 blackBackroundColor와 UIView의 당신에게 imageView 추가) ..... 그리고 지금은 [<yourView>.layer renderInContext:UIGraphicsGetCurrentContext()];에서이 방법을 사용하십시오. 난 그냥 뜻이 경계 정보

+0

이미지 크기가 조정될 때 검정색 배경 전체 화면 이미지 뷰 내부에 화면 맞춤. 어느 쪽이든, UIImage를 파일로 저장하면 흰색이고 비어 있습니다. – yosh

1
UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 480), NO, 0.0); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [self.view.layer renderInContext:context]; 
    yourImageViewToStoreCaptured = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

희망이 있습니다.

+0

저장있는 UIImage * yourImageViewToStoreCaptured 촬영려고. – yosh

+0

좋아, 해결, 들으 :) – yosh

1
-(IBAction)saveViewToPhotoLibrary:(id)sender 
{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    UIGraphicsBeginImageContext(screenRect.size); 

    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    [[UIColor blackColor] set]; 
    CGContextFillRect(ctx, screenRect); 

    [self.view.layer renderInContext:ctx]; 

    UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIImageWriteToSavedPhotosAlbum(screenImage,nil,nil,nil);           
    //fill cordinat in place of nil if u want only image comes and not button......ok thanks vijay// 
    UIGraphicsEndImageContext();  
}