iphone – 如何知道图像大小应用方面适合在UIImageView中的图像

iphone – 如何知道图像大小应用方面适合在UIImageView中的图像,第1张

概述我正在加载图像到模式为’Aspect Fit’的imageview。我需要知道我的图像缩放到的大小。请帮忙。 请参阅@保罗德兰格的答案,而不是这一个 我找不到任何东西在一个容易访问的变量,有这个,所以这里是强力的方式: - (CGSize) aspectScaledImageSizeForImageView:(UIImageView *)iv image:(UIImage *)im {floa 我正在加载图像到模式为’Aspect Fit’的imagevIEw。我需要知道我的图像缩放到的大小。请帮忙。解决方法 请参阅@保罗德兰格的答案,而不是这一个

我找不到任何东西在一个容易访问的变量,有这个,所以这里是强力的方式:

- (CGSize) aspectScaledImageSizeforImageVIEw:(UIImageVIEw *)iv image:(UIImage *)im {float x,y;float a,b;x = iv.frame.size.wIDth;y = iv.frame.size.height;a = im.size.wIDth;b = im.size.height;if ( x == a && y == b ) {           // image fits exactly,no scaling required    // return iv.frame.size;}else if ( x > a && y > b ) {         // image fits completely within the imagevIEw frame    if ( x-a > y-b ) {              // image height is limiting factor,scale by height        a = y/b * a;        b = y;    } else {        b = x/a * b;                // image wIDth is limiting factor,scale by wIDth        a = x;    }} else if ( x < a && y < b ) {        // image is wIDer and taller than image vIEw    if ( a - x > b - y ) {          // height is limiting factor,scale by height        a = y/b * a;        b = y;    } else {                        // wIDth is limiting factor,scale by wIDth        b = x/a * b;        a = x;    }}else if ( x < a && y > b ) {        // image is wIDer than vIEw,scale by wIDth    b = x/a * b;    a = x;}else if ( x > a && y < b ) {        // image is taller than vIEw,scale by height    a = y/b * a;    b = y;}else if ( x == a ) {    a = y/b * a;    b = y;} else if ( y == b ) {    b = x/a * b;    a = x;}return CGSizeMake(a,b);}
总结

以上是内存溢出为你收集整理的iphone – 如何知道图像大小应用方面适合在UIImageView中的图像全部内容,希望文章能够帮你解决iphone – 如何知道图像大小应用方面适合在UIImageView中的图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1087932.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存