Ask a question: When we put data archiving, CGPoint class can archive it? There are those custom drawing class can also contain image archive it, how archival storage. Reply: Objects can archive you can look NSObject + Autocoding this class to all types of archives Reply:
There are no related articles or refer to the following code ah? Reply: Reply:
Yang ~ ~ ~ ~ ~ ~ ~ ~ cry ~ ~ ~ ~ ~ ~ ~ ~ ~ Reply:
CGPoint package you will be able to NSValue Lane Reply: Reply: Are you asking CGPoint with UIImage archive it, just wrote a demo can ah.
1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue. @ Property (copy, nonatomic) UIImage * image; @ Property (copy, nonatomic) NSValue * point;
2) when it filed with encodeObject [Encoder encodeObject: image forKey: @ "ImageKey"]; [Encoder encodeObject: point forKey: @ "PointKey"];
3) when stored CGPoint point = CGPointMake (1.1, 2.2); NSValue * value = [NSValue valueWithCGPoint: point];
/ / Store the data to the class Archive * archivingData = [[Archive alloc] init]; archivingData.image = [UIImage imageNamed: @ "pic.jpg"]; archivingData.point = value;
NSMutableData * data = [[NSMutableData alloc] init];
/ / Write to file [Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path
4) obtained when NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.]; NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];
/ / Get the class Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"]; [Unarchiver finishDecoding]; self.imageView.image = archivingData.image; NSValue * value = archivingData.point; CGPoint point = [value CGPointValue]; NSLog (@ "% f | |% f", point.x, point.y);
Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue) Reply:
you are asking CGPoint with UIImage archive it, just wrote a demo can ah.
1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue. @ Property (copy, nonatomic) UIImage * image; @ Property (copy, nonatomic) NSValue * point;
2) when it filed with encodeObject [Encoder encodeObject: image forKey: @ "ImageKey"]; [Encoder encodeObject: point forKey: @ "PointKey"];
3) when stored CGPoint point = CGPointMake (1.1, 2.2); NSValue * value = [NSValue valueWithCGPoint: point];
/ / Store the data to the class Archive * archivingData = [[Archive alloc] init]; archivingData.image = [UIImage imageNamed: @ "pic.jpg"]; archivingData.point = value;
NSMutableData * data = [[NSMutableData alloc] init];
/ / Write to file [Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path
4) obtained when NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.]; NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];
/ / Get the class Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"]; [Unarchiver finishDecoding]; self.imageView.image = archivingData.image; NSValue * value = archivingData.point; CGPoint point = [value CGPointValue]; NSLog (@ "% f | |% f", point.x, point.y);
Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue)
Thank Yang Reply:
Are you asking CGPoint with UIImage archive it, just wrote a demo can ah.
1) inside a custom class inherits NSCoding with NSCopying, your point would be defined as NSValue. @ Property (copy, nonatomic) UIImage * image; @ Property (copy, nonatomic) NSValue * point;
2) when it filed with encodeObject [Encoder encodeObject: image forKey: @ "ImageKey"]; [Encoder encodeObject: point forKey: @ "PointKey"];
3) when stored CGPoint point = CGPointMake (1.1, 2.2); NSValue * value = [NSValue valueWithCGPoint: point];
/ / Store the data to the class Archive * archivingData = [[Archive alloc] init]; archivingData.image = [UIImage imageNamed: @ "pic.jpg"]; archivingData.point = value;
NSMutableData * data = [[NSMutableData alloc] init];
/ / Write to file [Data writeToFile: self.archivingFileRootPath atomically: YES] ;/ / archivingFileRootPath is saved path
4) obtained when NSData * data = [[NSMutableData alloc] initWithContentsOfFile: self archivingFileRootPath.]; NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];
/ / Get the class Archive * archivingData = [unarchiver decodeObjectForKey: @ "ArchivingData"]; [Unarchiver finishDecoding]; self.imageView.image = archivingData.image; NSValue * value = archivingData.point; CGPoint point = [value CGPointValue]; NSLog (@ "% f | |% f", point.x, point.y);
Of course, if you are doing the game, I suggest you put all those CGPoint NSArray inside it (into NSValue)
Thank Yang
say ~ Reply:
Yang brother, ask you a question ah ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Can you tell me your QQ? I asked you a very stupid question, I do not ~ ~ ~ ~ ~ ~ ~ ~ recently doing the project, Kusi ~ ~ ~ ~ ~ ~ ~ ~ better not ah Reply:
Yang brother ~ ~ ~ ~ ~ ~ Reply me back my ~ ~ ~ ~ ~ ~ ~ Reply:
Yang brother ~ ~ ~ ~ ~ ~ Reply me back my ~ ~ ~ ~ ~ ~ ~
- 347702498 What is the problem message, and I do not work when the q's. . Generally free night
No comments:
Post a Comment