NSString *filePath = @"../work/png/11.png";
NSFileManager *fm =[NSFileManager defaultManager];
if ([fm fileExistsAtPath:filePath])
{
NSString *filepathName =[filePath lastPathComponent];
NSDictionary *attr =[fm attributesOfItemAtPath:filePath error:nil];
//获取图片文件的大小
int sizeValue =[[attr objectForKey:NSFileSize] intValue];
//图片文件的最后修改时间
NSString *modifiedString = [attr objectForKey:NSFileModificationDate] ;
[lastModifiedField setStringValue:[NSString stringWithFormat:@"Last modified:%@",modifiedString]];
NSData *data =[[NSData alloc] initWithContentsOfFile:filePath];
NSImage *showImage = [[NSImage alloc] initWithData:data] ;
if(showImage != nil && [showImage isValid] )
{
//图片的宽高
NSString *imageSize = [NSString stringWithFormat:@&#
[Cocoa]_[初级]_[获取图片文件的属性值:如图片大小、位深度、宽高、最后修改日期]
最新推荐文章于 2022-11-29 11:49:56 发布
本文介绍了如何使用Objective-C的Cocoa框架来获取PNG图片文件的属性,包括图片的大小、最后修改日期、宽度、高度和位深度。通过`NSFileManager`获取文件属性,使用`NSImage`创建并显示图片,同时利用`NSBitmapImageRep`获取位深度信息。
摘要由CSDN通过智能技术生成