如何在iphone sdk中显示UIImageJPEGRepresentation图像

发布于 2024-09-27 10:01:00 字数 618 浏览 0 评论 0原文

我想使用 UIImageJPEGRepresentation 在 iphone 中添加图像,在下面的代码中我缺少一些我不知道如何添加的东西

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:gameObj.gameThumbnails]];   
UIImage *myImage=[UIImage imageWithData:data];

imageView.image=UIImageJPEGRepresentation(myImage, 90);// I am missing something here
[elementView addSubview:imageView];
[imageView release];  

 /*gameObj.gameThumbnails is an url like http://static.gamesradar.com/images/mb/GamesRadar/us/Games/X/X-Men%20Arcade/Bulk%20Viewer/360%20PS3/2010-10-11/192.168.30.167-image36_bmp_jpgcopy--game_thumbnail.jpg
*/

请帮助我解决这个问题

I want to use UIImageJPEGRepresentation to add the image in iphone, in below code i am missing some thing I don't know how to add

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:gameObj.gameThumbnails]];   
UIImage *myImage=[UIImage imageWithData:data];

imageView.image=UIImageJPEGRepresentation(myImage, 90);// I am missing something here
[elementView addSubview:imageView];
[imageView release];  

 /*gameObj.gameThumbnails is an url like http://static.gamesradar.com/images/mb/GamesRadar/us/Games/X/X-Men%20Arcade/Bulk%20Viewer/360%20PS3/2010-10-11/192.168.30.167-image36_bmp_jpgcopy--game_thumbnail.jpg
*/

Please help me out of this

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

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

发布评论

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

评论(3

千里故人稀 2024-10-04 10:01:00

你将比较质量设置为 90。它应该在 0.0 到 1.0 之间

u are setting comparison quality to 90. it should be between 0.0 to 1.0

好多鱼好多余 2024-10-04 10:01:00

UIImageJPEGRepresentation 函数返回一个 NSData(字节数组),它表示以 JPEG 压缩的图像的内容。

要显示它,只需直接使用 UIImage 即可。

imageView.image = myImage;

The UIImageJPEGRepresentation function returns an NSData (array of bytes) which represents a content of the image if compressed in JPEG.

To display it, you just need to use the UIImage directly.

imageView.image = myImage;
噩梦成真你也成魔 2024-10-04 10:01:00

确保您:

  • 将压缩质量设置为 0.9(必须在 0.0 - 1.0 之间)
  • 正确设置 UIImageView 的框架
  • 不要隐藏 UIImageView

如果仍然不起作用,请尝试以下操作:

[elementView bringSubviewToFront:imageView];

希望它有帮助

Make sure that you:

  • Set your compression quality to 0.9(it MUST be between 0.0 - 1.0)
  • Set the frame of the UIImageView correctly
  • Don't make that UIImageView hidden

And if it still doesn't work then try the following:

[elementView bringSubviewToFront:imageView];

Hope it helps

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