Tuesday, December 9, 2008

Masking an image

Original post from iPhone Developer Tips
Masking an image enables a developer to create images with irregular shapes dynamically.

The following is a function that takes two images and uses one to mask the other.

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

CGImageRef maskRef = maskImage.CGImage;

CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);

CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];

}


NOTE: The mask image cannot have ANY transparency. Instead, transparent areas must be white or some value between black and white. The more towards black a pixel is the less transparent it becomes.

Tuesday, December 2, 2008

Wifi related

If your application requires a wifi connection, add the UIRequiresPersistentWiFi key to Info.plist and set it True, it will display the wifi connection dialog if not connected.

To determine whether the currently active network connection is Wi-Fi or the carrier's network use the constant kSCNetworkReachabilityFlagsIsWWAN defined in SystemConfiguration/SCNetworkReachability.h . Look for the Reachability sample code.