如果您想缩小图像大小,我有一个阈值问题的答案和一种缩小图像并可靠地避免 Apple 查询的方法。
一些背景:
在我的应用程序中,我为用户提供了在通过电子邮件发送之前自动将其图像缩小到 1024x768 的选项,以避免 Apple 的“你想缩小图像吗?” 询问。
很长一段时间,我认为这个除垢量就足够了。但我发现,如果他们的图像中有足够的细节,那么即使在 1024x768 下,它仍然可以触发 Apple 的查询。
所以,下面的代码是我处理这个问题的方法。请注意,如果 getMinImgSizFlag 为 TRUE,我已经在其他地方将图像缩放为 1024x768。自动
//...convert the UIImage into NSData, as the email controller requires, using
// a default JPG compression value of 90%.
float jpgCompression = 0.9f;
imageAsNSData = UIImageJPEGRepresentation( [self camImage], jpgCompression );
if ( [gDB getMinImgSizFlag] == TRUE )
{
//...if we are here, the user has opted to pre emptively scale their
// image down to 1024x768 to avoid Apple's 'scale the image down?'
// query.
//
// if so, then we will do a bit more testing because even with
// the image scaled down, if it has a lot of fine detail, it may
// still exceed a critical size threashold and trigger the query.
//
// it's been empirically determined that the critical size threashold
// falls between 391K and 394K bytes.
//
// if we determine that the compressed image, at the default JPG
// compression, is still larger than the critical size threashold,
// then we will begin looping and increasing the JPG compression
// until the image size drops below 380K.
//
// the aproximately 10K between our limit, 380K, and Apple's
// critical size threashold allows for the possibility that Apple
// may be including the contribution of the E-Mail's text size into
// its threashold calculations.
while ( [imageAsNSData length] > 380000 )
{
jpgCompression -= 0.05f;
imageAsNSData = UIImageJPEGRepresentation( [self camImage], jpgCompression );
}
}
而已。我已经测试了这段代码,它可靠地让我避免了苹果的你想在通过电子邮件发送查询之前缩小你的图像。