Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Dynamic Mask
View Single Post
Old 03-12-2009, 06:38 AM   #3 (permalink)
indiantroy
Registered Member
 
Join Date: Mar 2009
Posts: 27
indiantroy is on a distinguished road
Default

Hi Flux,

I am trying to achieve the same thing you mentioned. I posted my question on this forum only but didn't get any answer unfortunately.

I tried to understand the code snippet you have posted but it seems that it is not complete and being a newbie to the iPhone App Dev, was not able to understand it wholly.

Would you mind sharing the complete code for me to understand the context? This would help me greatly in learning the masking thing.

Thanks in advance,
iTroy




Quote:
Originally Posted by flux View Post
Hi Everyone,

I have searched this forum several times now, and i do not seem to find an answer to my problem.

Other people have asked the same question already but i'm under the impression the problem is not as easy to solve.

Basically what i am trying to do is the following,

I would like to put a layer on top of a picture, and then erase that layer through touches or accelerometer movement, 'scratching away' the place where a touch has occured.

Like this:


Now i have got this working like this:
Code:
- (void)drawRect:(CGRect)rect {
     
     // Retrieve the graphics context
     CGContextRef context = UIGraphicsGetCurrentContext();
     
     //Get the drawing image
     CGImageRef maskImage = [self drawImageWithContext:context inRect:rect];
     
     // Get the mask from the image
     CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskImage)
                                                  , CGImageGetHeight(maskImage)
                                                  , CGImageGetBitsPerComponent(maskImage)
                                                  , CGImageGetBitsPerPixel(maskImage)
                                                  , CGImageGetBytesPerRow(maskImage)
                                                  ,  CGImageGetDataProvider(maskImage)
                                                  , NULL
                                                  , false);
     
     //make sure the images are not upside down
     CGContextTranslateCTM(context, 0, self.bounds.size.height);
     CGContextScaleCTM(context, 1.0, -1.0);
     
     //Draw the base picture
     CGContextDrawLayerInRect(context, rect, firstLayer);
     
     //Add clipping
     CGContextClipToMask(context, rect, mask);
     
     //Release the mask
     CGImageRelease(mask);

     //Release the maskImage
     CGImageRelease(maskImage);
     
     //draw the second layer
     CGContextDrawLayerInRect(context, rect, secondLayer);
}
As you can see i have a drawrect method, where i make an image based on the touches. This image is being used to get an imageMask.

I draw the first picture, lay down the mask, and then draw the second picture.

This works effectively resolving my problem.

But there are two drawbacks:
1) If i draw another thing over my last picture, this is also clipped...
2) Perhaps the most important thing, when i call my drawrect several times (from accelerometer), i lose performance, making the application impossible to use...

So basically my question is,

is there another way on resolving my problem? Do i need to look at this another way? Do i need to copy paste pixels?
Do i need alpha blending? Or do i need to look at OpenGL?

I'm hoping somebody can finally shed some light on this, because i'm really sitting in the dark here...
indiantroy is offline   Reply With Quote
 

» Advertisements
» Online Users: 455
15 members and 440 guests
baja_yu, buggen, CatfishBlues Games, ChrisYates, foany, jbro, mer10, mraalex, n00b, Paul Slocum, PavelMik, QuantumDoja, ryantcb, sadevb61, TheStalker
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,635
Threads: 94,096
Posts: 402,802
Top Poster: BrianSlick (7,990)
Welcome to our newest member, sadevb61
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.