更改 UIImageView 顶部和底部的 alpha 值
我正在从相册中选取一张照片,但是我希望能够对其执行以下操作:
更改顶部和底部部分的 alpha 值(假设顶部 20 个像素和顶部 20 个像素)从底部开始)
然后复制仅中间未更改的部分并将其分配给另一个 UIImageView
我有以下代码:
@synthesize imageView, croppedImageView, choosePhotoBtn, takePhotoBtn;
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
/* then here I want to change the alpha value of the top and bottom parts */
/* then copy the unchanged part then assign it to the image value of croppedImageView */
}
I'm picking up a photo from the photo albums, however I would like to be able to do the following with it:
Change the alpha value of the top and bottom parts (lets say 20 pixles from the top and 20 pixles from the bottom) to 0.5
then copy only the unchanged part in the middle and assign it to another UIImageView
I've got this code:
@synthesize imageView, croppedImageView, choosePhotoBtn, takePhotoBtn;
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
/* then here I want to change the alpha value of the top and bottom parts */
/* then copy the unchanged part then assign it to the image value of croppedImageView */
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为实现这一点的最佳方法是使用蒙版图像。您可以在此博客文章中找到一个很好的示例: http://iosdevelopertips .com/cocoa/how-to-mask-an-image.html
I think the best way to achieve this is to use a mask image. You can find a good example on this blog post : http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html