UIImage

UIImage* image = [[UIImage alloc] initWithData:data];
 
 
 
//UIImage -> NSData
 
//PNG形式
NSData *pngData = [[NSData alloc] initWithData:UIImagePNGRepresentation(image)];
 
//JPEG形式
NSData *pngData = [[NSData alloc] initWithData:UIImageJPEGRepresentation(image)];
 
 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ファイル名だけで読み込む  キャッシュ有り。(流用向き)
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
UIImage *image = [UIImage imageNamed:@"Incoming.png"];
 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
パスを指定して読み込む キャッシュ無し。(流用不向き、同じファイルを頻繁に読む込むことがある場合、気をつける)
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
UIImage* image = [UIImage imageWithContentsOfFile:path];
 
 
 
 
 
 
 
/**
 *  指定角度に回転したイメージを返す
 *  @param image 元イメージ
 *  @param angle 角度
 *  @return 回転したUIImage
 */
- (UIImage *)rotatedImage:(UIImage *)image
angle:(NSInteger)angle
{
    CGSize imgSize = {image.size.width, image.size.height};
    UIGraphicsBeginImageContext(imgSize);
    CGContextRef context = UIGraphicsGetCurrentContext();
    // 回転の中心点を移動する
    CGContextTranslateCTM(context, image.size.width/2, image.size.height/2);
    // Y軸方向を補正する
    CGContextScaleCTM(context, 1.0, -1.0);
 
    float radian = angle * M_PI / 180;
    CGContextRotateCTM(context, radian);
    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(-image.size.width/2, -image.size.height/2, image.size.width, image.size.height), image.CGImage);
 
    UIImage *rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
 
    return rotatedImage;
}
最終更新:2018年03月05日 16:29