获取本地照片,的尺寸

来源:互联网 发布:au下载 免费中文版mac 编辑:程序博客网 时间:2024/06/11 19:45

NSFileManager * fileManager = [NSFileManagerdefaultManager];

    NSString * filePath = [[NSHomeDirectory()stringByAppendingPathComponent:@"/Documents"]stringByAppendingPathComponent:[NSStringstringWithFormat:@"camera%ld.png",currentBtn]];

    

    //path 图片的本地路径

//    CGSize size=[UIImage imageWithContentsOfFile:filePath].size;


  CGImageRef imageRef = [[UIImage imageWithContentsOfFile:filePath] CGImage];

    CGSize size = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));//这个size就是实际图片的像素大小 例如系统相册里的花, {1239,822}

       //2、获得屏幕分辨率 scale

   CGFloat scale_screen = [UIScreen mainScreen].scale;

//所以要想展示 imageView上面图片的大小

      UIImageView * imgView =[[UIImageViewalloc]init] ;

      imgView.center = self.view.center;

       imgView.bounds = CGRectMake(0, 0, size.width/scale_screen, size.height/scale_screen);

     imgView.image = [[UIImage alloc]initWithContentsOfFile:filePath ];


//第二种是苹果官方的

     UIImageView * imgView =[[UIImageViewalloc]initWithFrame:CGRectMake(0,0, WIDTH,HEIGHT)] ;

      imgView.image = [[UIImagealloc]initWithContentsOfFile:filePath ];

        imgView.contentMode =UIViewContentModeScaleAspectFit;//  关于介绍 contentMode :     http://blog.csdn.net/annkie/article/details/49247755

        [self.view addSubview:imgView];


1 0