更改UIImageView顶部和底部的alpha值

时间:2011-07-02 01:08:23

标签: iphone objective-c uiimagepickercontroller crop alpha-transparency

我正在从相册中挑选一张照片,不过我希望能够用它来做以下事情:

  1. 更改顶部和底部的alpha值(从顶部开20个像素,从底部开20个像素)到0.5

  2. 然后只复制中间的未更改部分并将其分配给另一个UIImageView

  3. 我有这段代码:

    @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 */
    
    }
    

1 个答案:

答案 0 :(得分:1)

我认为实现这一目标的最佳方法是使用遮罩图像。您可以在此博客文章中找到一个很好的示例:http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html