-1
您好我正在激發一個交易,但由事務結果一個結果來作爲blob屬性,即圖像,我想改變該blob屬性爲圖像 我爲那個「圖標」是從交易中取圖像的關鍵, 所以請幫我看看這個, 圖像打印爲零, 爲什麼?Blob圖像轉換
NSString *inputString = [[[self formModel] attributeAsString:@"icon"] description];
NSLog(@"icon is %@",[[self formModel] attributeAsString:@"icon"]);
NSLog(@"inputstring is %@",inputString);
//NSImage *image = [NSUnarchiver unarchiveObjectWithData:[[self formModel] attributeAsString:@"icon"]];
// NSLog(@「image is%@」,image);
NSArray *words = [inputString componentsSeparatedByString:@" "];
NSLog(@"words is %@",words);
NSArray *sizes = [words valueForKey:@"length"];
int sizeOfBytes = 0;
for (NSNumber *size in sizes) {
sizeOfBytes += [size intValue]/2;
}
int bytes[sizeOfBytes];
int counts = 0;
for (NSString *word in words) {
// convert each word from string to int
NSMutableString *ostr = [NSMutableString stringWithCapacity:[word length]];
while ([word length] > 0) {
[ostr appendFormat:@"%@", [word substringFromIndex:[word length] - 2]];
word = [word substringToIndex:[word length] - 2];
}
NSScanner *scaner = [NSScanner scannerWithString:ostr];
unsigned int val;
[scaner scanHexInt:&val];
bytes[counts] = val;
counts++;
}
// get NSData form c array
NSData *data = [NSData dataWithBytes:bytes length:sizeOfBytes];
NSLog(@"My NSDATA %@",data);
NSImage *Image = [[NSImage alloc] initWithData:data];