0
我節省了我的文檔dir..I圖像不與巴紐問題或.jpeg images.I我能在iPhone中正確顯示它們。但是來到.JPG,我不能夠display.Please幫我this.THANKS IN ADVANCE如何.JPG圖像保存爲巴紐或.jpeg在iphone
+(void)DownloadImage:(NSString*)ImagePath{
if ([ImagePath isEqualToString:@""]) {
return;
}
UIImage *dimage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://1xyz/uploads/%@",ImagePath]]]];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"pathIMAGEPATHS:::::::%@",ImagePath);
NSLog(@"path:::::::%@",docDir);
NSArray *patharr=[ImagePath componentsSeparatedByString:@"."];
NSString* Ext=[NSString stringWithFormat: @"%@",[patharr objectAtIndex:1]];
NSString *FilePath = [NSString stringWithFormat: [NSString stringWithFormat:@"%@/%@",docDir,ImagePath]];
NSLog(@"%@/%@",docDir,ImagePath);
if([Ext isEqualToString:@"png"])
{
NSLog(@"saving png");
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(dimage)];
[data1 writeToFile:FilePath atomically:YES];
}
else if([Ext isEqualToString:@"jpeg"])
{
NSLog(@"saving jpeg");
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(dimage, 1.0f)];//1.0f = 100% quality
[data2 writeToFile:FilePath atomically:YES];
}
else
{
NSData *data3 = [NSData dataWithData:UIImageJPEGRepresentation(dimage, 1.0f)];
[data3 writeToFile:FilePath atomically:YES];
}
NSLog(@"saving image done");
[dimage release];
}