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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-11-2009, 08:29 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 21
Default differences between device and simulator

I've been using quartz to mask part of a screen capture, and on my iPod Touch it works fine, however on the simulator the image never gets masked.
What I'm doing is taking a screenshot, cropping the section I want to mask out, shrinking it to the size of the mask, then calling a function which applies the mask. On the iPod it works, on the simulator it does all the cropping and scaling, but not the clipping to mask.

I'm mainly concerned because I only have the one iPod Touch to test on, and I don't want it to work on other devices the way it works on the simulator.

I'm supplying the code that does the clipping, as well as the code that calls the clipping function in the hope that someone can tell me why it works differently on the device than on the simulator

Code:
- (UIImage *)clipImage:(UIImage *)imageIn withMask:(UIImage *)maskIn atRect:(CGRect) maskRect
{
    //Begin the drawing context
    UIGraphicsBeginImageContext(maskRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // Create the masked clipping region
    CGContextClipToMask(ctx, maskRect, maskIn.CGImage);
    // Compensate for inverted coordinate system
    CGContextTranslateCTM(ctx, 0.0, maskRect.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
	
    // Draw into context
    CGContextDrawImage(ctx, CGRectMake(0, 0, imageIn.size.width, imageIn.size.height), imageIn.CGImage);
    // Get the image and end the context
    imageIn = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return imageIn;
}

- (void)doClip:(id)sender
{
    //load the mask image
    UIImage* mask1 = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mask1.png"]];
    //captue screen
    UIImage* screenCap = [self captureView:[theDelegate window]];
    //crop area we want to apply the mask to
    screenCap = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([screenCap CGImage],CGRectMake(10, 25, 300, 300))];
    //shrink it to the size of the mask
    screenCap = [self imageWithImage:screenCap scaledToSize:CGSizeMake(150, 150)];
    //apply the image mask	
    UIImage* cropped = [self clipImage:screenCap
                              withMask:mask1
                                atRect:CGRectMake(0,0,150,150)];
    //trim some extra stuff off
    CGImageRef finalImage = CGImageCreateWithImageInRect([cropped CGImage], CGRectMake(10, 10, 128, 128));
    maskedImageView.image = [UIImage imageWithCGImage:finalImage];
}
death_au is offline   Reply With Quote
Old 03-12-2009, 02:40 AM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 36
Default

I wouldn't use the Simulator for anything but basic evaluation. My first app worked brilliantly on the Simulator but exhibited all sorts of problems on a real iPhone. The only way to test an app properly is with ad-hoc on a real iPhone. Ignore the Simulator in general except for build warnings and errors.
Kuroyume is offline   Reply With Quote
Old 03-12-2009, 06:58 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 21
Default

Quote:
Originally Posted by Kuroyume View Post
I wouldn't use the Simulator for anything but basic evaluation. My first app worked brilliantly on the Simulator but exhibited all sorts of problems on a real iPhone. The only way to test an app properly is with ad-hoc on a real iPhone. Ignore the Simulator in general except for build warnings and errors.
I understand that, but as you just said, it worked BETTER on the simulator, whereas mine is working worse. And with a lack of devices to test on, I'm paranoid that something will go wrong on an older device or something.

Plus it's quicker to compile and test little stuff on the simulator (then check it all works fine on the iPod after all the little stuff is in), and it's annoying that my images won't crop as they should. Being the simulator though it IS just an annoyance and nothing more. I just hope it all works right elsewhere...
death_au is offline   Reply With Quote
Old 03-16-2009, 04:22 AM   #4 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 36
Default

If it works 'worse' on the simulator, oh well. The real test of mettle is on a real device - and the simulator is not an 'emulator' so there are things that will appear to work well on the simulator and fail on a real iPhone. The simulator is good for testing build errors/warnings and some GUI quirks but I, as others have said, wouldn't put any faith in it as a final arbitor.
Kuroyume is offline   Reply With Quote
Old 06-04-2009, 10:58 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 5
Default

I've also noticed a difference between the simulator and the device for clipping masks. It worked in the simulator but not on the iPhone/iPod. I figured out my problem. The image I was using as a mask had a transparent background when it should have been white. Once I changed it to white, the mask worked properly on the iPhone/iPod. Maybe that's the same problem you had too.


Quote:
Originally Posted by death_au View Post
I've been using quartz to mask part of a screen capture, and on my iPod Touch it works fine, however on the simulator the image never gets masked.
What I'm doing is taking a screenshot, cropping the section I want to mask out, shrinking it to the size of the mask, then calling a function which applies the mask. On the iPod it works, on the simulator it does all the cropping and scaling, but not the clipping to mask.

I'm mainly concerned because I only have the one iPod Touch to test on, and I don't want it to work on other devices the way it works on the simulator.

I'm supplying the code that does the clipping, as well as the code that calls the clipping function in the hope that someone can tell me why it works differently on the device than on the simulator

Code:
- (UIImage *)clipImage:(UIImage *)imageIn withMask:(UIImage *)maskIn atRect:(CGRect) maskRect
{
    //Begin the drawing context
    UIGraphicsBeginImageContext(maskRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // Create the masked clipping region
    CGContextClipToMask(ctx, maskRect, maskIn.CGImage);
    // Compensate for inverted coordinate system
    CGContextTranslateCTM(ctx, 0.0, maskRect.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
	
    // Draw into context
    CGContextDrawImage(ctx, CGRectMake(0, 0, imageIn.size.width, imageIn.size.height), imageIn.CGImage);
    // Get the image and end the context
    imageIn = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return imageIn;
}

- (void)doClip:(id)sender
{
    //load the mask image
    UIImage* mask1 = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"mask1.png"]];
    //captue screen
    UIImage* screenCap = [self captureView:[theDelegate window]];
    //crop area we want to apply the mask to
    screenCap = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([screenCap CGImage],CGRectMake(10, 25, 300, 300))];
    //shrink it to the size of the mask
    screenCap = [self imageWithImage:screenCap scaledToSize:CGSizeMake(150, 150)];
    //apply the image mask	
    UIImage* cropped = [self clipImage:screenCap
                              withMask:mask1
                                atRect:CGRectMake(0,0,150,150)];
    //trim some extra stuff off
    CGImageRef finalImage = CGImageCreateWithImageInRect([cropped CGImage], CGRectMake(10, 10, 128, 128));
    maskedImageView.image = [UIImage imageWithCGImage:finalImage];
}
wrichard is offline   Reply With Quote
Old 07-10-2009, 09:43 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 2
Default

Quote:
Originally Posted by wrichard View Post
I've also noticed a difference between the simulator and the device for clipping masks. It worked in the simulator but not on the iPhone/iPod. I figured out my problem. The image I was using as a mask had a transparent background when it should have been white. Once I changed it to white, the mask worked properly on the iPhone/iPod. Maybe that's the same problem you had too.
With OS 2.2 it seems that when neither the main image nor the mask image have a transparency layer then whether or not the clip works on device or on the simulator is variable. When the main image has a transparency layer with a pixel set as transparent and the mask image doesn't have a transparency layer but with the masked pixels coloured black it seems to work reliably on both device and on the simuator.
chrisnew is offline   Reply With Quote
Reply

Bookmarks

Tags
clip, crop, device, mask, simulator

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 240
16 members and 224 guests
ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, Grinarn, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0