图像是NSData格式我想转换成图像文件

时间:2015-03-20 04:58:35

标签: ios image nsdata

图片是NSData格式我要转换成图片文件PLZ可以任何人帮我提前谢谢。

for (int i = 0; i < [[[ListingStep2Model sharedInstance] imagesAssetArray]count]; i++) {

        NSMutableArray *images = [NSMutableArray arrayWithCapacity:[[[ListingStep2Model sharedInstance] imagesAssetArray]count]];

        NSLog(@"Imges:%@", [[[ListingStep2Model sharedInstance] imagesAssetArray] objectAtIndex:i]);


        for (NSDictionary *dict in [[ListingStep2Model sharedInstance] imagesAssetArray]) {

            if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto){

                if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
                    UIImage* image = [dict objectForKey:UIImagePickerControllerOriginalImage];
                    [iPhoneXMPPAppDelegate load_uploadingImage:[image fixOrientation]];
                    NSData* data = UIImageJPEGRepresentation([iPhoneXMPPAppDelegate get_upload_image], 1.0f);
                    [Base64 initialize];
                    NSString *strEncoded = [Base64 encode:data];
                    strEncoded = [strEncoded stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];

                    NSMutableDictionary *param = [NSMutableDictionary dictionary];
                    [param setObject:strEncoded forKey:[NSString stringWithFormat:@"image%d",i]];
                    [temP addObject:param];

                } else {
                    NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);
                }
            }
        }
    }



    [iPhoneXMPPAppDelegate startIndicator];

    NSMutableArray *totalrequest = [[NSMutableArray alloc] init];
    [totalrequest addObject:param];

    [RequestAndResponseHandlers helparucommonRequestAndResponseHandlerWithParam:[NSDictionary dictionaryWithObjectsAndKeys:totalrequest,@"request",nil] methodName:methodName completionHandler:^(NSDictionary *response) {

        NSLog(@"Response :%@", response);

        if ([[response valueForKeyPath:@"response.httpCode"] integerValue]==200) {
          [[iPhoneXMPPAppDelegate appdelegate] navigateTo:[iPhoneXMPPAppDelegate publicView ]];
        }
        else {
            [iPhoneXMPPAppDelegate alertWithTitle:@"Alert" message:@"Please try again!"];
        }

        [iPhoneXMPPAppDelegate stopIndicator];

        [self.containerTbl reloadData];
    }];

}

输出图像文件在nsdata中

4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAEcKADAAQAAAABAAAC9gAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs%2BEJ%2B/8AAEQgC9gRwAwERAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5%2Bv/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5%2Bjp6vLz9PX29/j5%2Bv/bAEMAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/bAEMBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/dAAQAjv/aAAwDAQACEQMRAD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JEIpE8wqYxjY8TFWyuSneSSX4/wD2qX5W63vY2c0oNPfpfy1S

2 个答案:

答案 0 :(得分:0)

你只需要一行:

UIImage *convertedImage=[UIImage imageWithData:yourImageData];

答案 1 :(得分:0)

您可以像这样从NSData获取UIImage

NSData *data = yourData;

UIImage *image = [UIImage imageWithData:data];