关闭

iOS 图片压缩以及保存到doucument的方法

标签: 图片ios开发iOS
597人阅读 评论(0) 收藏 举报
分类:

#pragma mark - image_To_Samll

-(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;

}


#pragma mark 保存图片到document

- (void)saveImage:(UIImage *)tempImage WithName:(NSString *)imageName

{

    NSData* imageData = UIImagePNGRepresentation(tempImage);

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

    NSString* documentsDirectory = [paths objectAtIndex:0];

    // Now we get the full path to the file

    NSString* fullPathToFile = [documentsDirectorystringByAppendingPathComponent:imageName];

    // and then we write it out

 }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:78272次
    • 积分:1038
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:11篇
    • 译文:0篇
    • 评论:1条
    最新评论