データベースから画像を表示しようとしています。
この部分はうまく機能します。次のようにDBに画像を保存します:
UIImage *resizedImg = [Generics scaleImage:self.photo.image toResolution:self.photo.frame.size.width and:self.photo.frame.size.height];
NSData *imgData = UIImageJPEGRepresentation(resizedImg, 0.9);
NSString *stringDataImage = [NSString stringWithFormat:@"%@",imgData];
[dict setObject:stringDataImage for key@"image"];
// POST Request to save the image in DB ...
画像を読み込んで設定しようとすると、次のUIImageView
ようになります。
NSData *data = [[[MyUser sharedUser] picture] dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]];
または
NSData *data = [[[MyUser sharedUser] picture] dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
self.imageView.image = [UIImage withData:data];
しかし、これはうまくいきません。
data
と等しくありませんimgData
。エンコーディングだと思いますが、良いものを見つけることができます。nil[UIImage withData:data]
を返します。
手伝って頂けますか?
編集 :
変換して保存
UIImage *resizedImg = [Generics scaleImage:self.photo.image toResolution:self.photo.frame.size.width and:self.photo.frame.size.height];
NSData *imgData = UIImageJPEGRepresentation(resizedImg, 0.9);
[dict setObject:[imgData base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength] forKey:@"image"];
画像を読み込む
NSData *data = [[NSData alloc] initWithBase64EncodedData:[[MyUser sharedUser] picture] options:kNilOptions];
NSLog(@"%@", data);
self.image.image = [UIImage imageWithData:data];