标签:
(UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize { // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this new context, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage; } -(NSString *)ImageBase64String:(NSString *)path image:(UIImage *)oimage{ UIImage *_originImage = nil; if (path) { _originImage = [UIImage imageWithContentsOfFile:path]; }else{ _originImage = oimage; } NSData *_data = UIImageJPEGRepresentation(_originImage, 1.0f); // NSString *_encodedImageStr = iOS_Agin7?[_data base64Encoding]:[_data base64EncodedDataWithOptions:0]; NSString *_encodedImageStr = nil; if ([_data respondsToSelector:@selector(base64EncodedDataWithOptions:)]) { // It exists, so let‘s call it _encodedImageStr = [_data base64EncodedStringWithOptions:0]; } else { // Use the old API _encodedImageStr = [_data base64Encoding]; } // NSLog(@"===Encoded image:\n%@", _encodedImageStr); return _encodedImageStr; }
标签:
原文地址:http://www.cnblogs.com/keyan1102/p/4487037.html