2

小さい画像(100 * 100)から大きい画像(1000 * 1000)をこのように使用したいのですが、これは最悪の方法です。

ここでビューに追加しましたが、コンテキストで描画して保存したいと思います。

for(int j=0;j<5;j++)
      {
          for(int i=0;i<5;i++)
           {
         UIImageView* imgView = [[UIImageView alloc] initWithImage:  [UIImageimageNamed:@"images.jpeg"]];
          [imgView drawRect:CGRectMake(xCoord,yCoord,imgView.frame.size.width, imgView.frame.size.height)]; 
         yCoord =imgView.frame.size.height*j;

         [self.view addSubview:imgView];
          xCoord += imgView.frame.size.width;

          }
           yCoord=0;
           xCoord = 0.0;
       }

コンテキストdrawrectを使用して実行したいと思います。 CGContextDrawImageこれに対処する方法助けてください。よろしくお願いします。

4

3 に答える 3

2

コンテキストで描画したい場合は[image drawAsPatternInRect:rect]

編集:

このメソッドは、指定されたサイズの新しい画像を生成します。コンテキスト全体が満たされるまで、画像が繰り返し描画されます。

UIImage * TiledImage(UIImage *tile, CGSize size) {
    UIGraphicsBeginImageContext(size);
    [tile drawAsPatternInRect:CGRectMake(0,0, size.width, size.height)];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

あなたの場合は、次のように書いUIImage *bigImage = TiledImage([UIImageimageNamed:@"images.jpeg"], CGSizeMake(1000,1000));てください。これで、1000x1000ピクセルの画像ができました。

于 2012-10-17T09:35:34.550 に答える
0

これは、1000x1000を持ち、そのプロパティをにUIView設定すると得られるもののように見えますbackgroundColor

[UIColor colorWithPatternImage:@"images.jpeg"];

ただし、コンテキストで描画したい場合:

CGContextRef context = UIGraphicsBeginImageContext(imageSize);
[patternImage drawAsPatternInRect:imageRect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
于 2012-10-17T09:30:45.877 に答える
0

この方法で、任意のビューに背景パターンを適用できます。

UIImage *pattern = [UIImage imageNamed:@"yourimage-pattern.png"];
yourView.backgroundColor = [UIColor colorWithPatternImage:pattern];

これはあなたが現在持っているアプローチよりも簡単だと思います。

編集:

必要に応じて、コンテキストでビューをレンダリングし、スクリーンショットを撮ることができます。

UIGraphicsBeginImageContext(CGSizeMake(1000,1000)));
[yourView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

このコードスニペットQuartzCore libのヘッダーファイルを使用し、参照していることを確認してください。#import <QuartzCore/QuartzCore.h>

于 2012-10-17T09:31:01.913 に答える