2

我想使用 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
*/

请帮我解决这个问题

4

3 回答 3

13

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

于 2010-10-14T10:31:27.747 回答
3

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

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

imageView.image = myImage;
于 2010-10-14T10:31:34.300 回答
0

确保您:

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

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

[elementView bringSubviewToFront:imageView];

希望能帮助到你

于 2012-01-20T14:17:32.443 回答