Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage small+medium+large like apple Mail

Is there any reference tutorial for getting the image size in small or medium environment.

I just want to know the calculation of image sizes in terms of Width and Height, How can we calculate UIImage size in pixels when It is small, medium or large like in apple mail.

It is just like when we attach image in Mail it asks small, medium, large..

Plz don't provide this as I already gone through this..

Thanks in advance.

like image 817
Mehul Mistri Avatar asked Feb 20 '23 23:02

Mehul Mistri


1 Answers

Finally seeing from many solutions I got the following solution and done code according this.

We can get images like following.

Small = 320 pixels on longest edge JPEG
Medium = 640 pixels on longest edge JPEG
Large =  1296 pixels on longest edge JPEG

Where typeOfImage = 0,1,2 for small, medium and large respectively.

-(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;
}

and call to function like this

CGSize size = [self getImageWithRespectiveSize:imgOriginal withType:0];
like image 158
Mehul Mistri Avatar answered Feb 23 '23 14:02

Mehul Mistri