调整 NSData 大小以设置到 UIImage 中

发布于 2024-09-13 08:10:57 字数 277 浏览 2 评论 0原文

我有这些代码:

UIImage * img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMAGEURL]]];
[self.imageView setImage:img];

但是 IMAGEURL 包含高分辨率图片,因此需要很长时间才能加载。我可以将图像数据调整得更小以加快加载速度吗?

任何帮助将不胜感激。

谢谢。

I have these codes:

UIImage * img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:IMAGEURL]]];
[self.imageView setImage:img];

But the IMAGEURL contains a high resolution picture so it takes much time to load. Can I resize the image data smaller to load faster?

Any help will be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2024-09-20 08:10:57

不,为了调整图像大小,您至少应该将其读取一次,因此除非服务器为您提供低质量版本,否则您无能为力。

除非你很勇敢并且图像是 JPEG:libjpeg 有一个函数可以读取按 2、4 或 8 倍下采样的图像。例如,对于 1/8 比例,它读取 DCT 块并仅采用常数分量。但这会稍微复杂一些。阅读时间将大大减少。

请参阅 iphone-reading-an-area-of-an-image关于这一点也是如此。

No, in order to resize the image you should at least read it in once, so unless the server has a low-quality version for you, there's nothing you can do.

Unless you're brave and the image is JPEG: libjpeg has a function to read in images downsampled by a factor of 2, 4 or 8. E.g. for scale 1/8 it reads DCT blocks and takes only the constant component. But this will be a little more complex. Read time will be drastically reduced.

See iphone-reading-an-area-of-an-image about this as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文