mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-06 08:22:23 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user