gpt4 book ai didi

ios - UIImagePickerController 正确地在其上叠加图像

转载 作者:行者123 更新时间:2023-11-28 22:13:41 25 4
gpt4 key购买 nike

关于这个问题:

  • 设备:第 4 代 iPod touch(640 * 960 视网膜显示分辨率)
  • 操作系统:iOS 6
  • 开发工具包:XCode 5.0.2
  • 我尝试修改的源代码: PhotoPicker example
  • 目标:在 UIImagePickerController View 顶部添加图像

描述:

我正在修改 PhotoPicker example来自 Apple,旨在在拍照前添加显示在相机镜头上方的自定义 PNG 图像。该图像将指示用户必须将他/她的脸放在哪里。

下图显示了我得到的和我想要的。如您所见,原始图像似乎确实进行了重新缩放并且变得太大

enter image description here

点击“相机”按钮时调用的主要方法如下。我对其进行了修改,将 UIImageView subview 添加到 imagePickerController,其中我使用包含原始 640*960 图像的 UIImage 初始化了 UIImageView。

当我在我的第 4 代 iPod (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):

enter image description here

然而这是结果:

enter image description here

最佳答案

确保您的图像具有这样的视网膜后缀:

image@2x.png

关于ios - UIImagePickerController 正确地在其上叠加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22303303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com