相关疑难解决方法(0)

使用宽高比调整UIImage的大小?

我正在使用此代码调整iPhone上的图像大小:

CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0);
UIGraphicsBeginImageContext(screenRect.size);
[value drawInRect:screenRect blendMode:kCGBlendModePlusDarker alpha:1];
UIImage *tmpValue = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

只要图像的宽高比与新调整大小的图像的宽高比相匹配,哪个工作正常.我想修改它,以便保持正确的宽高比,并在图像不显示的任何地方放置黑色背景.所以我仍然会得到一张320x480的图像,但在顶部和底部或两侧都有黑色,具体取决于原始图像尺寸.

有没有一种简单的方法来做到这一点类似于我正在做的事情?谢谢!

iphone core-graphics uiimage ios

37
推荐指数
1
解决办法
3万
查看次数

CGImageGetWidth(workingImage.CGImage)和workingImage.size.width之间有什么区别吗?

有什么区别CGImageGetWidth(workingImage.CGImage)workingImage.size.width?第一个更快还是更安全?我知道在第二种情况下,我直接获得了值.

image-processing objective-c quartz-graphics uiimage ios

3
推荐指数
2
解决办法
4373
查看次数

以编程方式将图像600x600调整为100x100

我有高度为600的图像,宽度也是600现在我想在UIImageView中用100x100以编程方式显示该图像.我尝试但是图像不像原始图像我添加图像的屏幕截图首先是100x100,第二个是200x200.第二个很好.但是第一个不像原始图像.知道我做什么请在此输入图像描述

in.h中

@interface ViewController : UIViewController
{
    IBOutlet UIImageView *imageView1;
    IBOutlet UIImageView *imageView2;
}
@end
Run Code Online (Sandbox Code Playgroud)

In.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageView1.frame=CGRectMake(100, 50, 100, 100);
    imageView2.frame=CGRectMake(50, 200, 200, 200);
    imageView1.image = [UIImage imageNamed:@"Untitled-7.png"];
    imageView2.image = [UIImage imageNamed:@"Untitled-7.png"];
}
Run Code Online (Sandbox Code Playgroud)

原始图像是600x600

iphone objective-c

1
推荐指数
3
解决办法
1万
查看次数