iPhone:如何使用PIxel在UIImage中设置alpha?

时间:2012-01-03 12:05:06

标签: iphone objective-c uiimage pixel alpha

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{


    NSSet *allTouches = [[event allTouches] retain];
    switch ([allTouches count])
    {
           case 1: {
           UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
           CGPoint touchPoint =  [touch locationInView:[self view]];
                if(touchPoint.x > rightleg.frame.origin.x && touchPoint.x < rightleg.frame.origin.x + rightleg.frame.size.width &&
                   touchPoint.y > rightleg.frame.origin.y && touchPoint.y < rightleg.frame.origin.y + rightleg.frame.size.height ){
                   rightleg.alpha = rightleg.alpha + 0.005;
                }
            }
        case 2 :{
            UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
            CGPoint touchPoint =  [touch locationInView:[self view]];
            if(touchPoint.x > leftleg.frame.origin.x && touchPoint.x < leftleg.frame.origin.x + leftleg.frame.size.width &&
               touchPoint.y > leftleg.frame.origin.y && touchPoint.y < leftleg.frame.origin.y + leftleg.frame.size.height ){
               leftleg.alpha = leftleg.alpha + 0.005;

            }
        }
    }


}

当用户触摸Image时,此代码在UIImage上设置为alpha,但是当触摸该像素时如何在UIImage中设置像素?

1 个答案:

答案 0 :(得分:0)

您必须将UIImage转换为字节数组,进行更改,然后再次保存到UIImage。

这样的事情可能有所帮助: