0

重複の可能性:
UIImageのトリミング

画像のトリミングに関するチュートリアルをたくさん見て、運試しをしていますが、成功しませんでした。

AVFoundationから画像をトリミングする必要があります。カメラから画像を撮影するときは、ポートレートモードから左に回転するため、右に回転する必要があり、xとyは反対になります。問題は、画像のフレームを配置する場所に送信すると、画像のサイズと長方形に相関関係がないように見えることです。

コードは次のとおりです。

@property (weak, nonatomic) IBOutlet UIView *videoPreviewView;
...
...
int width = videoPreviewView.frame.size.width;
int height = videoPreviewView.frame.size.height;
int x = videoPreviewView.frame.origin.x;
int y = videoPreviewView.frame.origin.y;
CGRect croprect = CGRectMake(y, x,height,width);
// Draw new image in current graphics context
CGImageRef imageRef = CGImageCreateWithImageInRect([sourceImage CGImage], croprect);
// Create new cropped UIImage
UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:[sourceImage scale] orientation:UIImageOrientationRight];

フレームのサイズを印刷すると、次のようになります。

(4.5,69.5,310,310)

画像サイズは次のとおりです。

(720,1280)

任意の画像解像度でトリミングを実行するにはどうすればよいですか?

値に-を掛けてみましたimage.scaleが、値は1.00です

4

2 に答える 2

1

これを試してみてください.これは間違いなくあなたを助けます. https://github.com/barrettj/BJImageCropper

于 2013-02-04T05:50:46.010 に答える
0
To resize image, Try this    

    UIImage *image = [UIImage imageNamed:@"image.png"];

    CGSize itemSize = CGSizeMake((your Width), (your Height));
    UIGraphicsBeginImageContext(itemSize);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
    [image drawInRect:imageRect];

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

To Crop,

    // Create new image context
    UIGraphicsBeginImageContext(SIZE);

    // Create CGRect for image
    CGRect newRect = CGRectMake(x, y,SIZE.width,SIZE.height);

    // Draw the image into the rect
    [ORIGINALIMAGE drawInRect:newRect];

    // Saving the image, ending image context
    UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
于 2013-02-04T05:19:52.577 に答える