Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:42:27+00:00 2026-06-09T04:42:27+00:00

I have been able to redraw a UIImage with a border successfully, but not

  • 0

I have been able to redraw a UIImage with a border successfully, but not with a border + shadow. The code below successfully draws the image with a white border, but I cannot figure out how to include a drop shadow under the border. Help is greatly appreciated!

- (UIImage *)generatePhotoFrameWithImage:(UIImage *)image {
    CGSize newSize = CGSizeMake(image.size.width + 50, image.size.height + 60);
    UIGraphicsBeginImageContext(newSize);
    CGRect rect = CGRectMake(25, 35, image.size.width, image.size.height);
    [image drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextStrokeRectWithWidth(context, CGRectMake(25, 35, image.size.width, image.size.height), 50);
    
    //CGContextSetShadowWithColor(context, CGSizeMake(0, -60), 5, [UIColor blackColor].CGColor);
    
    UIImage *result =  UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return result;
}

PS: I am not using a UIImageView because I need to preserve the full image quality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:42:28+00:00Added an answer on June 9, 2026 at 4:42 am

    You need to call CGContextSetShadowWithColor before you stroke the border, so the border will cast a shadow.

    If you don’t want the border to cast a shadow onto the image, you need to set up a transparency layer in which you draw both the image and the border. You can read about transparency layers in the Quartz 2D Programming Guide.

    If you want to preserve image quality, you need to use UIGraphicsBeginImageContextWithOptions and pass in the scale of the original image.

    - (UIImage *)generatePhotoFrameWithImage:(UIImage *)image {
        CGSize newSize = CGSizeMake(image.size.width + 50, image.size.height + 60);
        CGRect rect = CGRectMake(25, 35, image.size.width, image.size.height);
    
        UIGraphicsBeginImageContextWithOptions(newSize, NO, image.scale); {
            CGContextRef context = UIGraphicsGetCurrentContext();
    
            CGContextBeginTransparencyLayer(context, NULL); {
                [image drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
    
                CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
                CGContextSetShadowWithColor(context, CGSizeMake(0, 5), 5, [UIColor blackColor].CGColor);
                CGContextStrokeRectWithWidth(context, CGRectMake(25, 35, image.size.width, image.size.height), 50);
            } CGContextEndTransparencyLayer(context);
        }
        UIImage *result =  UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing a lot of reading but I have not been able
I have been able to find methods like -[NSString stringWithCString:encoding:] but they do not
I have been able to successfully execute other methods using reflection but I am
I have been able to Archive on Xcode 4 successfully, but all of a
I have been able to create ASPX pages without the code behind, but I
I have been able to store the height for my image in a variable:
I have been able to change the 'location' of my images with RewriteRule, but
I have been searching here for some time but haven't been able to find
I have been searching everywhere for this and not been able to find it
Using Javascript I have been able to select an image element (an HTMLImageElement object,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.