iphone 图片等比例缩小
来源:互联网 发布:网络诈骗七万判几年 编辑:程序博客网 时间:2024/05/01 05:24
- (CGSize)setoriginW: (CGSize)imageWH setoriginH:(CGSize)originWH{ float dWidth = imageWH.width; //img的宽高 float dHeight = imageWH.height; float dAspectRatio = dWidth/dHeight; //纵横比 float dPictureWidth = originWH.width; float dPictureHeight = originWH.height; //传图的宽高 float dPictureAspectRatio = dPictureWidth/dPictureHeight; //长宽比 if (dPictureAspectRatio > dAspectRatio){ float nNewHeight = dWidth/dPictureWidth*dPictureHeight; newImage = CGSizeMake(dWidth, nNewHeight); }else if (dPictureAspectRatio < dAspectRatio){ float nNewWidth = dHeight/dPictureHeight*dPictureWidth; newImage = CGSizeMake(nNewWidth, dHeight); NSLog(@"newImage = %f \n %f",newImage.width,newImage.height); } return newImage;}///其它方法,,,不太合适各种图片// sizeWidth = originWH.width; //图的宽// sizeHeight = originWH.height; //图的高// // float imgwidth = imageWH.width; //视图的宽// float imgHeght = imageWH.height; //视图的高// float w = 0;// float h = 0;// // if (sizeWidth >= imgwidth && sizeHeight <= imgHeght) {// // newWidth = imgwidth;// newHeight = (imgHeght * sizeHeight) / sizeWidth;// }// // else if(imgwidth <= sizeWidth && imgHeght >= sizeHeight){// // newHeight = imgHeght;// newWidth = imgHeght * sizeWidth / sizeHeight;// // }// // else if (sizeWidth >= imgwidth && sizeHeight >= imgHeght){// // if(sizeWidth / sizeHeight >= imgwidth / imgHeght)// {// newWidth = imgwidth;// newHeight = (imgHeght * sizeHeight) / sizeWidth; // }// // if(sizeWidth / sizeHeight <= imgwidth / imgHeght)// {// newHeight = imgHeght;// newWidth = imgHeght * sizeWidth / sizeHeight;// }// }// // else// {// newWidth = sizeWidth;// newHeight = sizeWidth;// } --------------------------------------------// if(sizeWidth > 0 && sizeHeight > 0){ // if(imgwidth / sizeHeight >= imgwidth / imgHeght){ // if(sizeWidth > imgwidth){ // newImage.width = imgwidth; // newImage.height = (sizeHeight * imgwidth) / sizeWidth; // }else{ // newImage.width = sizeWidth; // newImage.height = sizeHeight; // } // }else{ // if(sizeHeight > imgwidth){ // newImage.height = imgHeght; // newImage.width=(sizeWidth * imgHeght) / sizeHeight; // }else{ // newImage.width = sizeWidth; // newImage.height = sizeHeight; // } // } // } ------------------------------ // 原始宽高在指定宽高范围内,不作任何处理// if (sizeWidth <= imgwidth && sizeHeight <= imgHeght) {// newImage.width = sizeWidth;// newImage.height = sizeHeight;// }else{// //取得比例系数// w = sizeWidth / imgwidth;// h = sizeHeight / imgHeght;// NSLog(@"\nwwwwwwwwww=====%f\nhhhhhhhhhhhh====%f",w,h);// }// if (w > h) {// newImage.width = imgwidth;// newImage.height = (float)(w >= 1 ? roundf(imgHeght / w) : roundf(imgHeght * w));// }// // 宽度比小于高度比// else if (w < h )// {// newImage.height = imgHeght;// newImage.width = (float)(h >= 1 ? roundf(imgwidth / h) : roundf(imgwidth * h));// }// // 宽度比等于高度比 // else // { // newImage.width = imgwidth; // newImage.height = imgwidth; // } //