1

どういうわけかプログラムで1つのImageViewの印刷画面を作成できますか?

さまざまなサイズで、画面サイズに自動的に拡大縮小され(AspectFit)、中央に配置され、背景が黒の大きな写真を表示しているとします。黒のimageview背景を含む拡大縮小された画像をキャプチャして、320x480の画像を処理したいと思います。

では、たとえば350x600の画像を320x480に変更し、境界線を黒にして、この画像ビューに他の要素(ボタン、ラベル)をオーバーレイしないようにするにはどうすればよいでしょうか。Androidではスクリーンバッファをキャプチャしているだけですが、iPhoneではどうすればよいかわかりません...

前もって感謝します!

4

3 に答える 3

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が出力されます。このようなロジックを使用できるように黒の境界線が必要な場合imageViewは、UIViewにblackBackroundColor黒として追加します(境界線を設定できるように、このビューのフレームはimageViewのフレームよりも大きく、両側に余裕を持たせる必要があります)。 ....そして現在 [<yourView>.layer renderInContext:UIGraphicsGetCurrentContext()];この方法を使用しています。

于 2011-04-13T09:24:43.410 に答える
1
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 480), NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];
    yourImageViewToStoreCaptured = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

お役に立てれば。

于 2011-04-13T09:19:34.190 に答える
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();    
}
于 2011-04-13T09:21:12.647 に答える