如何通过单击不透明按钮来调整 url 中的图像大小?
我对 Objective 还很陌生,我正在尝试增强 iPhone 应用程序(由其他人完成的编码)。我正在尝试从互联网上提取图像并将其显示为缩略图。
这个想法是让用户单击按钮(其后面的图像不透明)并将其调整为完整尺寸 - 覆盖整个屏幕。
这是我的按钮操作的 .m 文件代码:
-(IBAction)changeFullSize{
test.text = @"YOU HAVE CLICKED!";
// grab the original image
CGSize newSize = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(newSize);
[urlImage.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
我认为调整大小之类的事情很容易,但由于某种原因我无法做到正确。谢谢!
I'm pretty new to objective and I'm trying to enhance an iPhone app (coding done by someone else). I'm trying to pull an image from the internet and its displayed as a thumbnail.
The idea is to have the user click the button (opaque with the image behind it) and have it resize to full size - covering the whole screen.
This is my .m file code for the button action:
-(IBAction)changeFullSize{
test.text = @"YOU HAVE CLICKED!";
// grab the original image
CGSize newSize = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(newSize);
[urlImage.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
I thought something like resizing would be easy but I just can't get it right for some reason. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能将图像放入 UIImageView 并将内容模式设置为 UIViewContentModeScaleToFill 吗?然后点击按钮时将 UIImageview 的大小调整为全屏?
can't you just put your image into a UIImageView and set the content mode to UIViewContentModeScaleToFill? Then just resize the UIImageview to full screen when the button is tapped?