gpt4 book ai didi

ios - UIImagePickerController - 将图片裁剪成圆形

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:49 30 4
gpt4 key购买 nike

如何使用图像选择器 Controller 裁剪圆形图像?

我在我的项目中显示的图片是圆形的,使用下面的代码

 CALayer *image = profileImageView.layer;
[image setCornerRadius:50];
[image setMasksToBounds:YES];

[image setBorderColor:[[UIColor whiteColor]CGColor]];
[image setBorderWidth:5];

到目前为止,我有这段代码可以裁剪图像,但它只会使它们变成正方形

   - (void)showPhotoLibary
{
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)) {
return;
}

UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

// Displays saved pictures from the Camera Roll album.
mediaUI.mediaTypes = @[(NSString*)kUTTypeImage];

// Hides the controls for moving & scaling pictures
mediaUI.allowsEditing = YES;


mediaUI.delegate = self;


[self presentViewController:mediaUI animated:YES completion:nil];
}


- (void) imagePickerController: (
UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

UIImage *originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
self.profileImageView.image = originalImage;



[picker dismissViewControllerAnimated:YES completion:nil];

}

最佳答案

进口#import <QuartzCore/QuartzCore.h>在你的.h文件中

   self.profileImageView.layer.cornerRadius = imageView.frame.size.width/2;  //or 20.0
self.profileImageView.layer.masksToBounds = YES;

关于ios - UIImagePickerController - 将图片裁剪成圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23676602/

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