1

ユーザーがカメラから写真を撮るたびに、複数の画像を 1 つずつステッチする必要があるアプリを開発しています。

これは、2つの画像をマージするために使用しているものです。

[self performSelector:@selector(joinImages:secondImage:) withObject:firstimage withObject:imageCaptured];

- (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


    //Joins 2 UIImages together, stitching them horizontally
    CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
    UIGraphicsBeginImageContext(size);

    CGPoint image1Point = CGPointMake(0, 0);
    [im1 drawAtPoint:image1Point];

    CGPoint image2Point = CGPointMake(im1.size.width,0);
    [im2 drawAtPoint:image2Point];

    UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    firstimage=finalImage;// final images updated everytime

    [pool release];
    return finalImage;
}

しかし、これを iPhone で実行するとメモリ警告が表示され、iPod では問題なく動作します。

また、iPhoneの場合は画像がトリミングされます。

この問題を解決するために私にできることは何でも。

ありがとう..

4

2 に答える 2

1

このようなことができます。

 - (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
   {   
    @autoreleasepool
    {
       //Joins 2 UIImages together, stitching them horizontally
       CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
      UIGraphicsBeginImageContext(size);

      CGPoint image1Point = CGPointMake(0, 0);
      [im1 drawAtPoint:image1Point];

      CGPoint image2Point = CGPointMake(im1.size.width,0);
      [im2 drawAtPoint:image2Point];

      UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      firstimage=finalImage;// final images updated everytime

      return finalImage;
   }   
 }

これがうまくいくことを願っています。

于 2013-10-22T11:01:58.697 に答える
0
 [self joinImages:firstimage secondImage:secondImage];

- (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Joins 2 UIImages together, stitching them horizontally
 CGSize size = CGSizeMake(im1.size.width+im2.size.width, im2.size.height);
 UIGraphicsBeginImageContext(size);

 CGPoint image1Point = CGPointMake(0, 0);
 [im1 drawAtPoint:image1Point];

 CGPoint image2Point = CGPointMake(im1.size.width,0);
 [im2 drawAtPoint:image2Point];

 UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 firstimage=finalImage;// final images updated everytime

 [pool release];
 return finalImage;
 }
于 2013-10-22T13:20:48.950 に答える