是否有任何参考教程可以在中小型环境中获取图像大小。
我只想知道根据宽度和高度计算图像大小,我们如何计算大小,中等或大的像UII图像大小(如苹果邮件)。
就像我们在邮件中附加图像时要求小,中,大......
Plz不提供this因为我已经经历了这个......
提前致谢。
答案 0 :(得分:7)
最后从许多解决方案中看到我得到了以下解决方案并根据此完成了代码。
我们可以获得如下图像。
Small = 320 pixels on longest edge JPEG
Medium = 640 pixels on longest edge JPEG
Large = 1296 pixels on longest edge JPEG
其中typeOfImage = 0,1,2分别为小,中,大。
-(CGSize)getImageWithRespectiveSize:(UIImage *)pImage withType:(NSInteger)typeOfImg
{
CGSize pSize;
if(typeOfImg == 0)
pSize = [self getCGSizesOfImages:320 andImage:pImage];
else if(typeOfImg == 1)
pSize = [self getCGSizesOfImages:640 andImage:pImage];
else if(typeOfImg == 2)
pSize = [self getCGSizesOfImages:1296 andImage:pImage];
else
pSize = CGSizeMake(pImage.size.width, pImage.size.height);
return pSize;
}
-(CGSize)getCGSizesOfImages:(NSInteger)pIntPixels andImage:(UIImage *)pImage
{
CGSize pSize;
if(pImage.size.width > pImage.size.height)
{
CGFloat tmp = pImage.size.height/pImage.size.width*pIntPixels;
pSize = CGSizeMake(pIntPixels, tmp);
}
else if(pImage.size.width < pImage.size.height)
{
CGFloat tmp = pImage.size.width/pImage.size.height*pIntPixels;
pSize = CGSizeMake(tmp, pIntPixels);
}
else
{
CGFloat tmp = pImage.size.height/pImage.size.width*pIntPixels;
pSize = CGSizeMake(tmp, pIntPixels);
}
return pSize;
}
并调用像这样的函数
CGSize size = [self getImageWithRespectiveSize:imgOriginal withType:0];
答案 1 :(得分:1)
您可以使用imageIO框架,设置调整图像大小的方法非常容易。周围有很多样本,这里是谷歌的第一个热门,它也解释了核心图形的经典方式。 uiimage scaling
[编辑]
如果您正在查看如何获得以字节为单位的大小,可以查看Apple Large Image Downsizing