1

画面イメージ リンクsavePic イメージ リンク、screenImg と savePic の違いを見つけることができます。backgroundImageView を非常に小さな png に設定しました。backgroundimageview を Picture に保存したい。高解像度の画像を保存する方法を誰か教えてください。

- (void)viewDidLoad
{
    [super viewDidLoad];
    //_backImgView 320*480
    self.backImgView.image = [UIImage imageNamed:@"Purple.png"];

    [self performSelector:@selector(savePic) withObject:nil afterDelay:0.1];
}

- (void)savePic
{
    BOOL isDir;
    NSString *dirPath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/Pic"]; 
    NSFileManager *fm = [NSFileManager defaultManager];
    if(![fm fileExistsAtPath:dirPath isDirectory:&isDir]){
        BOOL bo = [fm createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil];
        if(!bo){
            NSLog(@"-->Create CardSlide Dir Fail!!!");
            return;
        }
    }

    UIGraphicsBeginImageContext(_backImgView.bounds.size);
    //UIGraphicsBeginImageContextWithOptions(_backImgView.bounds.size, _backImgView.opaque, 2.0);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    [_backImgView drawRect:_backImgView.bounds];
    //[_backImgView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *bgImg = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();

    NSString *path = [NSString stringWithFormat:@"save_%@.jpg", @"demo"];
    NSString *jpgPath = [dirPath stringByAppendingPathComponent:path]; 
    BOOL isSucc = [UIImageJPEGRepresentation(bgImg, 1.0) writeToFile:jpgPath atomically:YES];
    NSLog(@"%@ write photo %@!", jpgPath, isSucc?@"SUCC":@"FAIL");
}
4

1 に答える 1

0

小さな画像を使用すると、それを正しい方法でより大きな画像にスケーリングすることは不可能です。常にぼやけてノイズの多い画像が表示されますが、画像に伸縮可能な繰り返し部分がある場合は、新しい画像を作成せずに画像の内部を引き伸ばすことができます. UIImage には次の 2 つの API が呼び出されます:
– resizableImageWithCapInsets:(ios5 のみ)
– stretchableImageWithLeftCapWidth:topCapHeight:(iOS 5.0 では非推奨)
正しいインセットが見つかった場合、新しい画像の作成を回避できます。基本的には、メッセージ アプリケーションでバブルを作成するために使用されるのと同じシステムです。バルーンは非常に小さいですが、縦横比を維持する伸縮可能な領域があります。
画像は非常にシンプルなので、rect パスを作成する Quartz 関数を使用して描画することも考えられます。パスは「ほぼ」解像度に依存せず、正しいサイズにスケーリングする必要があります。

于 2012-06-19T06:12:33.143 に答える