一个从UIImageView中获得Image位置的函数

简介: (CGRect)getFrameSizeForImage:(UIImage *)image inImageView:(UIImageView *)imageView { float hfactor = image.size.width / imageView.frame.size.width; float vfactor = image.size.he

 
 (CGRect)getFrameSizeForImage:(UIImage *)image inImageView:(UIImageView *)imageView {
    
    float hfactor = image.size.width / imageView.frame.size.width;
    float vfactor = image.size.height / imageView.frame.size.height;
    
    float factor = fmax(hfactor, vfactor);
    
    // Divide the size by the greater of the vertical or horizontal shrinkage factor
    float newWidth = image.size.width / factor;
    float newHeight = image.size.height / factor;
    
    // Then figure out if you need to offset it to center vertically or horizontally
    float leftOffset = (imageView.frame.size.width - newWidth) / 2;
    float topOffset = (imageView.frame.size.height - newHeight) / 2;
    
    return CGRectMake(leftOffset, topOffset, newWidth, newHeight);
}

废话不多说贴代码。再stackOverflow中找到的马克下!

目录
相关文章
|
图形学
unity3d置灰image图片shader
新建材质球,赋值该shader,将材质球复制到image上即可置灰image Shader "UIEffect/ImageGray" { Properties { [PerRendererData] _MainTex("...
1447 0
UITextView根据NSString计算Size
UITextView根据NSString计算Size
42 0
VC中GDI+双缓冲实现Picture控件中显示png图片
VC中GDI+双缓冲实现Picture控件中显示png图片
167 0
|
数据采集 前端开发 JavaScript
|
存储 JavaScript 前端开发
Image图片查找不存在时(九)
在实际的开发中,常常会遇到关于图片的问题。 如图片显示的问题,然而在显示图片的过程中,常常也会遇到一些问题,如图片不存在,图片引用的路径不匹配等。
260 0
VC2005中将Picture控件显示图片保存为BMP,JPG等格式
1.在stdafx.h头文件中加入   #include 2.保存图片   方法一:     HBITMAP hBitmap = NULL; //创建位图段 BITMAPINFO bmi; LPBYTE pBits; ZeroMemory(&bmi,sizeof(bmi)); //m...
973 0