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 09-02-2009, 09:29 AM   #10 (permalink)
smsawant
Registered Member
 
Join Date: Apr 2009
Posts: 82
smsawant is on a distinguished road
Default

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...
hi flux,

i have two images which are overlaping on each other.(the way in which cards are placed on top of each other)

now if i move my finger over the top most image that portion of the image should become transparent.(opacity of that part should become 0).

i have tried following code on touch moved event to achieve this functionality which is working fine.But problem with this code is i am not getting appropriate finishing in it.
Code:
UIGraphicsBeginImageContext(frontImage.frame.size);
		[drawImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)];
		CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
		CGContextSetLineWidth(UIGraphicsGetCurrentContext(),10.0);
		CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 5);
		CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x,lastPoint.y);
		CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, frontImage.frame.size.width, frontImage.frame.size.height));
		CGContextStrokePath(UIGraphicsGetCurrentContext());
		CGContextFlush(UIGraphicsGetCurrentContext());
		frontImage.image = UIGraphicsGetImageFromCurrentImageContext();
		UIGraphicsEndImageContext();
i does not have clear idea how can i do it?

kindly help me out or give me some pointer.

Thanks in advance

Last edited by smsawant; 09-02-2009 at 10:22 AM.
smsawant is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,180
Threads: 93,920
Posts: 402,153
Top Poster: BrianSlick (7,967)
Welcome to our newest member, mausumi
Powered by vBadvanced CMPS v3.1.0

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