How to mask a square image into an image with round corners in iOS?

You can use CoreGraphics to create a path for a round rectangle with this code snippet: static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight) { float fw, fh; if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, rect); return; } CGContextSaveGState(context); CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect)); CGContextScaleCTM (context, ovalWidth, ovalHeight); fw = CGRectGetWidth … Read more

Cropping center square of UIImage

I think here would be the perfect solution! It is NOT good idea to crop image basis on the toSize‘s size. It will look weird when the image resolution (size) is very large. Following code will crop the image as per the toSize‘s ratio. Improved from @BlackRider‘s answer. – (UIImage *)imageByCroppingImage:(UIImage *)image toSize:(CGSize)size { double … Read more

ios: change the colors of a UIImage

The easiest and shortest: Way to do that in case when you dealing with UIImageView: Obj-C: theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [theImageView setTintColor:[UIColor redColor]]; Swift: let theImageView = UIImageView(image: UIImage(named:”foo”)!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)) theImageView.tintColor = UIColor.redColor()

Resizing UIimages pulled from the Camera also ROTATES the UIimage?

The reason your code doesn’t work is because the imageOrientation on the code that you have is not being taken into account. Specifically, if the imageOrientation is right/left, then you need to both rotate the image and swap width/height. Here is some code to do this: -(UIImage*)imageByScalingToSize:(CGSize)targetSize { UIImage* sourceImage = self; CGFloat targetWidth = … Read more

How to combine/ merge 2 images into 1

You can create graphics context and draw both images in it. You’ll get an image result from both your source images combined. – (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage { UIImage *image = nil; CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height)); if (UIGraphicsBeginImageContextWithOptions != NULL) { UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]); } else { UIGraphicsBeginImageContext(newImageSize); } [firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2), roundf((newImageSize.height-firstImage.size.height)/2))]; … Read more

Difference between UIImage and UIImageView

Example: UIImage *bgImage = [UIImage imageNamed:@”Default@2x.png”]; UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:bgImage]; backgroundImageView.frame = [[UIScreen mainScreen] bounds]; UIImage Overview: A UIImage object is a high-level way to display image data. You can create images from files, from Quartz image objects, or from raw image data you receive. The UIImage class also offers several options for … Read more

Referencing image in a folder in asset catalog

Visual Instructions (based on Xcode 10.1) To have the path uniquely identify an asset catalog image, set the “Provides Namespace” attribute of the folder to true. 1) Select the asset catalog folder. *The folder is yellow if “Provides Namespace” is false. 2) Make sure the Inspectors panel is visible 3) In the Inspectors panel, select … Read more

How do I use the NSString draw functionality to create a UIImage from text

You can try this: (updated for iOS 4) -(UIImage *)imageFromText:(NSString *)text { // set the font type and size UIFont *font = [UIFont systemFontOfSize:20.0]; CGSize size = [text sizeWithFont:font]; // check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+) if (UIGraphicsBeginImageContextWithOptions != NULL) UIGraphicsBeginImageContextWithOptions(size,NO,0.0); else // iOS is < 4.0 UIGraphicsBeginImageContext(size); // optional: add a shadow, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)