我的问题是:我正在从服务器获取图像。当我从服务器图像大小 138x91 获取图像时,我已经给出了我的图像大小在我的自定义单元格大小 85x56 中。它的加载很好。但是,当我单击行时,它会增加服务器图像的大小。如何在我的 tableview 中获取图像时减小图像尺寸以及如何在我单击行时不更改图像尺寸。如何解决我的问题。我想要从 url 获取图像以及如何在 iOS.goto 中减小图像尺寸下面的链接。
1).点击前。
http://radiokhushi.com/siri-admin/uploads/Beforclick.png
2).点击
http://radiokhushi.com/siri-admin/uploads/ofterclick.png
这是在索引路径的行单元格中获取数据代码的图像。并在我显示一个占位符图像之前加载。
newsobject.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[newsarry objectAtIndex:indexPath.row] objectForKey:@"thumb_file"]]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
[tableView cellForRowAtIndexPath:indexPath].imageView.image = image;
});
});
最佳答案
试试这个方法:
UIImage *croppedimg = [self imageWithImage:[UIImage imageNamed:@"image.png"] convertToSize:CGSizeMake(95, 95)]; // here resize your image whatever you want.
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
关于ios - 从 url 获取的图像以及如何在 iPhone 中减小图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23645787/