How to resize image pixel size programmatically


i am creating app using facebook. if i am trying to upload photo to facebook means i got following message any give idea for solve that

"The provided user_generated photo for an OG action must be at least 480px in both dimensions"


I use a function like follow to get an image with any size. Original image should big than you wanted.(ps:You can try an image little)

+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)wantSize { UIImage * targetImage; if (nil == image) { targetImage = nil; }else{ CGSize size = image.size; CGRect rect; if (wantSize.width/wantSize.height > size.width/size.height) { rect.size.width = wantSize.height*size.width/size.height; rect.size.height = wantSize.height; rect.origin.x = (wantSize.width - rect.size.width)/2; rect.origin.y = 0; } else{ rect.size.width = wantSize.width; rect.size.height = wantSize.width*size.height/size.width; rect.origin.x = 0; rect.origin.y = (wantSize.height - rect.size.height)/2; } UIGraphicsBeginImageContext(wantSize); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); UIRectFill(CGRectMake(0, 0, wantSize.width, wantSize.height));//clear background [image drawInRect:rect]; targetImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } return targetImage; }


You must provide a bigger image, with at least 480px width and height.


Your image is apparently smaller than 480px wide or tall. The problem is either that the original image is too small, or you're retrieving it incorrectly. You could, theoretically resize the image to make it bigger, but that will result in pixelation that is probably undesirable.

You should show us how you're retrieving the image. For example, when I want to pick a photo from my library, I'll use the code adapted from <a href="https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html#//apple_ref/doc/uid/TP40010408-SW1" rel="nofollow">Picking an Item from the Photo Library</a> from the <em>Camera Programming Topics for iOS</em>:

UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; // To instead show the controls to allow user to trim image, set this to YES; // If no cropping available, set this to NO. mediaUI.allowsEditing = YES; mediaUI.delegate = delegate;

And then, you obviously have to implement the didFinishPickingMediaWithInfo:

#pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; UIImage *originalImage, *editedImage, *imageToUse; // Handle a still image picked from a photo album if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) { editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage]; originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]; if (editedImage) { imageToUse = editedImage; } else { imageToUse = originalImage; } NSLog(@"image size = %@", NSStringFromCGSize(imageToUse.size)); if (imageToUse.size.width < 480 || imageToUse.size.height < 480) { [[[UIAlertView alloc] initWithTitle:nil message:@"Please select image that is at least 480 x 480" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } else { // do something with imageToUse } } [picker dismissViewControllerAnimated: YES completion:nil]; }


  • How to change color of some part of view from controller in swift?
  • How to detect error if archive of jar file failed?
  • The cast to value type 'Decimal' failed because the materialized value is null
  • How can I add overlay images or text on top of videos in Android?
  • drawing application for iOS performance issue
  • how to give UIImage negative color effect
  • How can I change the color of an element using a UIBezierPath?
  • UIScrollView not updating and displaying properly
  • Routing, polylines in iPhone Google Maps
  • TableViewCell to auto-resize its height according to content in xcode?
  • Subclassing UIToolbar and overriding drawRect: - UIBarButtonItems NOT displaying
  • Xamarin UI Test. Take control's background color ios
  • DirectX newb - Multisampled Texture2D with depth on a Billboard
  • Custom uinavigatonbar exception
  • How to create a customized rounded UiView and UIButton like MobilePASS?
  • Objective C Textfield Default Value “•••••••” to \"1•••••••”,“12•••••”,“123••••” when user cli
  • Mouse press slot for QComboBox - fill the items dynamically if user clicks the combobox
  • LLVM 3.0 compiler error: cast of C pointer type to Objective-C pointer type 'id' requires
  • Merge two imageViews into one and save iOS swift
  • String not fitting in label which is in a subview for swift
  • UITableViewCell change selectedBackgroundView alpha?
  • Solid Shadow in All Directions
  • windowScriptObject method not found on Objective-C code
  • UILabel extra spaces before and after text ios
  • Xamarin forms toggle button default color on IOS
  • UIButton Borders Function Only Gives Back White Borders
  • How secure are apple APNS push notifications?
  • How to define an array of floats in Shader properties?
  • WARNING:root:Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER. Wit
  • Loading fixtures in sails tests
  • How to render a pixel array most efficiently to a window in c++?
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • Assign variable to the value in HTML
  • How to use carriage return with multiple line?
  • Google Custom Search with transparent background
  • Android fill_parent issue
  • Repeat a vertical line on every page in Report Builder / SSRS
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Perl system calls when running as another user using sudo
  • How to apply VCL Styles to DLL-based forms in Inno Setup?