// grab the original image
UIImage *originalImage = [UIImage imageNamed:@"myImage.png"];
// scaling set to 2.0 makes the image 1/2 the size.
UIImage *scaledImage =
[UIImage imageWithCGImage:[originalImage CGImage]
scale:(originalImage.scale * 2.0)
orientation:(originalImage.imageOrientation)];
Showing posts with label image. Show all posts
Showing posts with label image. Show all posts
Stretching an UIImage while preserving the corners
myImageView.image = [myImageView.image resizableImageWithCapInsets:UIEdgeInsetsMake(20.f, 12.f, 19.f, 19.f)];
For lower iOS version, use
[UIImage stretchableImageWithLeftCapWidth:15 topCapHeight:13];
Resize UIImage
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Labels:
change,
image,
iphone SDK,
size
Make a UIImage from a MKMapView or Other View
The improved function for retina display:
- (UIImage*) renderToImage
{
if(UIGraphicsBeginImageContextWithOptions != NULL)
{
UIGraphicsBeginImageContextWithOptions(mapView.frame.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(mapView.frame.size);
}
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Set Rounded Corner to Image
UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
// You can even add a border
[l setBorderWidth:4.0];
[l setBorderColor:[[UIColor blueColor] CGColor]];
Labels:
border,
image,
iphone SDK,
round
add Image Border
iPhone SDK Tips & Tricks
#import <QuartzCore/QuartzCore.h>
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
Labels:
border,
image,
imageview,
iphone SDK
Subscribe to:
Posts (Atom)
