是否有可能找到UIImage的文件扩展名? [英] Is it possible to find the file extension of a UIImage ?

查看:320
本文介绍了是否有可能找到UIImage的文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从NSData或UIImage中查找图像类型有助于检查UIimage的四种不同图像类型

I found the below code in Finding image type from NSData or UIImage which helps to check four different image types of a UIimage

     (NSString *)contentTypeForImageData:(NSData *)data {
    uint8_t c;
    [data getBytes:&c length:1];

    switch (c) {
    case 0xFF:
        return @"image/jpeg";
    case 0x89:
        return @"image/png";
    case 0x47:
        return @"image/gif";
    case 0x49:
    case 0x4D:
        return @"image/tiff";
    }
    return nil;
}

我想知道如何找到文件是否是位图图像它有.bmp扩展名。有人可以请帮助我。修改上面的代码也可以找到bmp,或者请给我一些代码的解决方案。

I want to know how to find the file is a bitmap image or not that it has .bmp extension. can someone please help me with it. Either modify the above code to find bmp as well or please provide me a solution with some code.

感谢adnvance

thanks in adnvance

推荐答案

您可以使用

UIImageJPEGRepresentation将图像更改为 NSData < #UIImage * image#>,< #CGFloat compressionQuality#>)



UIImagePNGRepresentation(< ; #UIImage * image#>)

方法。以这种方式调用它:

You can, change image to NSData by using
UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
OR
UIImagePNGRepresentation(<#UIImage *image#>)
method. Call it in this way:

- (void) yourMethod{
    NSData *imageData = UIImagePNGRepresentation(yourImage);
    NSString *str = [self contentTypeForImageData:imageData];

}

- (NSString *)contentTypeForImageData:(NSData *)data {
    uint8_t c;
    [data getBytes:&c length:1];

    switch (c) {
        case 0xFF:
                return @"image/jpeg";
        case 0x89:
                return @"image/png";
        case 0x47:
                return @"image/gif";
        case 0x49:
            break;
        case 0x42:
            return @"image/bmp";
        case 0x4D:
            return @"image/tiff";
    }
    return nil;
}

这篇关于是否有可能找到UIImage的文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆