我有这两种方法。我怎么称呼他们?
//to base 64 string
-(NSString *)getStringFromImage:(UIImage *)image{
if(image){
NSData *dataObj = UIImagePNGRepresentation(image);
return [dataObj base64Encoding];
} else {
return @"";
}
}
//Convert back
// NSData *dataObj = [NSData dataWithBase64EncodedString:beforeStringImage];
// UIImage *beforeImage = [UIImage imageWithData:dataObj];
答案 0 :(得分:1)
如果要从同一个类调用该方法,可以按如下方式调用:
UIImage *image = [UIImage imageNamed:@"someimg.png"];
NSString *str = [self getStringFromImage:image];
否则,如果要从不同的类调用该方法,请执行以下操作:
假设clInstance
是具有该方法的类的实例,那么
UIImage *image = [UIImage imageNamed:@"someimg.png"];
NSString *str = [clInstance getStringFromImage:image];