-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFImageAsset.m
62 lines (59 loc) · 1.8 KB
/
SMFImageAsset.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// SMFImageAsset.m
// SMFramework
//
// Created by Thomas Cool on 12/11/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFImageAsset.h"
#import "SMFPhotoMethods.h"
#import "SMFMediaPreview.h"
@implementation SMFImageAsset
-(id)initWithPath:(NSString *)path
{
if (![SMFPhotoMethods isImageAtPath:path])
return nil;
self=[super init];
[_image release];
_image=[[BRImage imageWithPath:path] retain];
_path = [path retain];
[self setTitle:[_path lastPathComponent]];
return self;
}
-(NSDictionary *)orderedDictionary
{
NSMutableDictionary *a=[[NSMutableDictionary alloc] init];
if([_meta objectForKey:METADATA_TITLE]!=nil)
[a setObject:[_meta objectForKey:METADATA_TITLE] forKey:METADATA_TITLE];
NSArray *keys = [NSArray arrayWithObjects:@"Width",@"Height",@"Size",nil];
CGSize s = [_image pixelBounds];
NSArray *objects = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"%d Pixels",(int)s.width,nil],
[NSString stringWithFormat:@"%d Pixels",(int)s.height,nil],
[self fileSize],
nil];
[a setObject:keys forKey:METADATA_CUSTOM_KEYS];
[a setObject:objects forKey:METADATA_CUSTOM_OBJECTS];
return [a autorelease];
}
-(NSString *)fileSize
{
NSDictionary *att = [[NSFileManager defaultManager] attributesOfItemAtPath:_path error:nil];
double size = [[att objectForKey:NSFileSize] doubleValue];
int mod=0;
while (size>1024.0f) {
size=size/1024.0f;
mod++;
}
NSString *ext=@"B";
if (mod==1)
ext=@"KB";
else if(mod==2)
ext=@"MB";
else if(mod==2)
ext=@"GB";
else if(mod==2)
ext=@"TB";
return [NSString stringWithFormat:@"%.2f%@",size,ext,nil];
}
@end