关于这个问题:
说明
我正在修改Apple的PhotoPicker example,目的是在拍照前添加显示在相机镜头上方的自定义PNG图像。图像将指示用户必须放置他/她的脸部。
下图显示了我得到的和我想要的东西。正如您所看到的那样,原始图像似乎重新缩放,变得太大。
点击“相机”按钮时调用的主要方法如下。我修改了它将 UIImageView 子视图添加到 imagePickerController ,在那里我用包含原始640 * 960图像的UIImage初始化了UIImageView。
当我在我的iPod第4代(640 * 960)上运行这段代码时,似乎缩放的图像很多。如何修复下面的代码以使图像完美覆盖相机?(点应出现在中心,黑色边框出现在边框中)
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
{
[self.imageView stopAnimating];
}
if (self.capturedImages.count > 0)
{
[self.capturedImages removeAllObjects];
}
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
/*
The user wants to use the camera interface. Set up our custom overlay view for the camera.
*/
imagePickerController.showsCameraControls = NO;
// Set rear camera
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
/*
Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
*/
[[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
imagePickerController.cameraOverlayView = self.overlayView;
self.overlayView = nil;
UIImage * imageOfFaces = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo border" ofType:@"png"]];
UIImageView * imageViewOfFaces = [[UIImageView alloc] initWithImage:imageOfFaces];
[imagePickerController.view addSubview:imageViewOfFaces];
[imageViewOfFaces sizeToFit];
}
self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
全尺寸图片
这是我要叠加的PNG图像(640w * 960h像素):
然而这是结果:
答案 0 :(得分:2)
确保您的图片具有如下的视网膜后缀:
image@2x.png