-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#6832Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowp: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Steps to reproduce

this func work good but if i change to BitmapDescriptor.bytes(imageToBytesUint8List);
i have this error:

What is wrong?
Expected results
Need find solution for this error
Actual results
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): Failed to handle method call
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): java.lang.IllegalArgumentException: Cannot interpret [bytes, {bitmapScaling=auto, byteData=[B@420caa1, imagePixelRatio=1.0}] as BitmapDescriptor
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugins.googlemaps.Convert.toBitmapDescriptor(Convert.java:71)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugins.googlemaps.Convert.interpretMarkerOptions(Convert.java:452)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugins.googlemaps.MarkersController.addMarker(MarkersController.java:195)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugins.googlemaps.MarkersController.addMarkers(MarkersController.java:41)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugins.googlemaps.GoogleMapController.onMethodCall(GoogleMapController.java:385)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at android.os.Handler.handleCallback(Handler.java:900)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at android.os.Handler.dispatchMessage(Handler.java:103)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at android.os.Looper.loop(Looper.java:219)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at android.app.ActivityThread.main(ActivityThread.java:8668)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
E/MethodChannel#plugins.flutter.dev/google_maps_android_3(18423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
Code sample
Code sample
static generateCustomMarkersIconFromPath(String? path) async {
try {
if (path == null || path.isEmpty) {
return BitmapDescriptor.defaultMarker;
}
Uint8List bytes = File(path).readAsBytesSync();
bytes = (_resizeImage(bytes, 140, 140))!;
ui.Image image = await _convertImageFromUint8ListToCanvasImage(bytes);
final generatedImage = await _drawCanvas(image);
final ByteData? imageToBytes =
await generatedImage.toByteData(format: ui.ImageByteFormat.png);
if (imageToBytes == null) {
return BitmapDescriptor.defaultMarker;
}
final Uint8List imageToBytesUint8List = imageToBytes.buffer.asUint8List();
return BitmapDescriptor.bytes(imageToBytesUint8List);
} catch (e) {
return BitmapDescriptor.defaultMarker;
}
}
static Future<ui.Image> _drawCanvas(ui.Image image) async {
ui.PictureRecorder recorder = ui.PictureRecorder();
Canvas canvasRecord = Canvas(recorder);
PinCanavasDraw pinCanvasDraw = PinCanavasDraw(image: image);
pinCanvasDraw.paint(canvasRecord, const Size(200, 200));
var genratedImage = await recorder.endRecording().toImage(200, 200);
return genratedImage;
}
static Uint8List? _resizeImage(Uint8List data, width, height) {
Uint8List? resizedData = data;
ui_image.Image? img = ui_image.decodeImage(data);
ui_image.Image resized =
ui_image.copyResize(img!, width: width, height: height);
resizedData = Uint8List.fromList(ui_image.encodePng(resized));
return resizedData;
}
static Future<ui.Image> _convertImageFromUint8ListToCanvasImage(
Uint8List img) async {
final Completer<ui.Image> completer = Completer();
ui.decodeImageFromList(img, (ui.Image img) {
return completer.complete(img);
});
return completer.future;
}
}
class PinCanavasDraw extends CustomPainter {
PinCanavasDraw({
required this.image,
});
ui.Image image;
@override
void paint(Canvas canvas, Size size) async {
Paint paint1 = Paint()
..color = const Color.fromARGB(163, 0, 0, 0).withOpacity(0.8)
..strokeWidth = 1
..style = PaintingStyle.fill;
canvas.drawRect(const Rect.fromLTWH(23, 23, 154, 154), paint1);
Path pathPin = Path()
..moveTo(100, 200)
..lineTo(80, 170)
..lineTo(120, 170)
..close();
Path pathShadow = Path()..addRect(const Rect.fromLTWH(23, 23, 154, 154));
canvas.drawPath(pathPin, paint1);
canvas.drawShadow(pathShadow, const Color.fromARGB(255, 0, 0, 0), 3, false);
canvas.drawImage(image, const Offset(30, 30), Paint());
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]GrzywN, ahmad-amhan, Lerobindesbois and Chalwe19
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowp: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team