2

写真を撮るときにオーバーレイビューを追加したい。オーバーレイビューを正常に追加して、写真をキャプチャできます。

キャプチャボタンをタップすると、プレビューが表示されます。そのプレビュー画面では、オーバーレイビューが上下逆になっています(約20〜30px)。

使用ボタンを選択すると、撮影した画像がフォトアルバムに保存されます。その中で、画像は素晴らしいです。プレビュー中のみ逆さまになります。

以下のコードを添付しました。間違いを教えてください。

-(void)viewDidLoad {

// ...
// Some other actions...

OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

[picker setDelegate:self];  
picker.showsCameraControls = YES;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;

picker.wantsFullScreenLayout = YES;

picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 1.24299, 1.24299 );

picker.cameraOverlayView = overlay;

[self presentModalViewController:picker animated:YES];  
[picker release];

}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Save image
    UIImage *overlayImage  = [UIImage imageNamed:@"img3.png"]; //foverlayImage image

    CGSize newSize = image.size;
    UIGraphicsBeginImageContext( newSize );

    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

    // Apply supplied opacity if applicable
    [overlayImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

}


- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;

// Unable to save the image  
if (error)
    alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    // All is well
else 
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];

    [alert show];
    alert.delegate = self;
    [alert release];
}

OverlayView.mで

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Clear the background of the overlay:
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        // Load the image to show in the overlay:
        UIImage *overlayGraphic = [UIImage imageNamed:@"img3.png"];
        UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
        overlayGraphicView.frame = CGRectMake(0, 0, 320, 460);
        [self addSubview:overlayGraphicView];
        [overlayGraphicView release];

    }

    return self;
}

前もって感謝します。

4

1 に答える 1

0

ねえ、私は同じものを探していて、なぜそれが逆さまに見えるのかを説明するこのリンクに出くわしました!それがhttp://trandangkhoa.blogspot.co.uk/2009/07/iphone-os-drawing-image-and-stupid.htmlに役立つことを願っています

于 2012-10-10T13:44:36.497 に答える