修改map.takeSnap(false)方法源码,修改前卫星地图的截图文件大小3.6M修改后截图压缩到130k
android :
源码路径 node_modules@react-native-mapbox-glmapsandroid
ctmglsrcmainjavacommapbox
ctmglutilsBitmapUtils.java
public static String createBase64(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, outputStream);//文件类型修改成JPEG 质量修改成50
byte[] bitmapBytes = outputStream.toByteArray();
closeSnapshotOutputStream(outputStream);
//String base64Prefix = "data:image/png;base64,";
String base64Prefix = "data:image/jpeg;base64,";//文件类型修改成JPEG
return base64Prefix + Base64.encodeToString(bitmapBytes, Base64.NO_WRAP);
ios:
源码路径 node_modules@react-native-mapbox-glmapsiosRCTMGLRNMBImageUtils.m
+ (NSString *)createBase64:(UIImage *)image
{
//NSData *data = UIImagePNGRepresentation(image);
NSData *data = UIImageJPEGRepresentation(image,0.5);//文件类型修改成JPEG 质量修改成0.5
//return [NSString stringWithFormat:@"%@%@", @"data:image/png;base64,", [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]];
return [NSString stringWithFormat:@"%@%@", @"data:image/jpeg;base64,", [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]];//文件类型修改成JPEG
}