add toDataURL method for svg elements

Add toDataURL method for svg elements to get data64 data  of svg.(iOS)
Add example for this.
This commit is contained in:
Horcrux
2016-08-10 16:54:48 +08:00
parent f118ae2d67
commit 76a3e8e32d
5 changed files with 89 additions and 13 deletions
+1 -5
View File
@@ -20,15 +20,11 @@
* define <ClipPath></ClipPath> content as clipPath template.
*/
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathRef:(NSString *)clipPathRef;
- (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathRef;
- (void)defineTemplate:(__kindof RNSVGNode *)template templateRef:(NSString *)templateRef;
- (RNSVGNode *)getDefinedTemplate:(NSString *)tempalteRef;
- (void)defineBrushConverter:(RNSVGBrushConverter *)brushConverter brushConverterRef:(NSString *)brushConverterRef;
- (RNSVGBrushConverter *)getDefinedBrushConverter:(NSString *)brushConverterRef;
- (NSString *)getDataURL;
@end
+13 -4
View File
@@ -16,6 +16,7 @@
NSMutableDictionary<NSString *, RNSVGNode *> *clipPaths;
NSMutableDictionary<NSString *, RNSVGNode *> *templates;
NSMutableDictionary<NSString *, RNSVGBrushConverter *> *brushConverters;
CGRect _boundingBox;
}
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
@@ -47,6 +48,7 @@
templates = nil;
brushConverters = nil;
CGContextRef context = UIGraphicsGetCurrentContext();
_boundingBox = rect;
for (RNSVGNode *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
@@ -63,10 +65,17 @@
[node renderTo:context];
}
}
// CGImageRef image = CGBitmapContextCreateImage(context);
// NSData *imageData = UIImagePNGRepresentation([[UIImage alloc] initWithCGImage:image]);
// NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
// NSLog(base64);
}
- (NSString *)getDataURL
{
UIGraphicsBeginImageContextWithOptions(_boundingBox.size, NO, 0);
[self drawRect:_boundingBox];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
UIGraphicsEndImageContext();
return base64;
}
- (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor