weixin_39895881
weixin_39895881
2020-11-28 21:09

Bad image quality with toDataURL()

We are using toDataURL() when the map should move similar to #50. However, the generated image is of bad quality. For testing, we removed the following lines in the toDataURL method in PluginMap.java:


float density = Resources.getSystem().getDisplayMetrics().density;
image = PluginUtil.resizeBitmap(image,
                                (int)(image.getWidth() / density),
                                (int)(image.getHeight() / density));

After that change, the generated images looks exactly like it looked on the native map. Is there any way to disable or properly configure that resize without changing the plugin's code?

该提问来源于开源项目:mapsplugin/cordova-plugin-googlemaps

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

12条回答

  • weixin_39942400 weixin_39942400 5月前

    I just want good quality of images If we can achieve that without downgrading performance, in simply removing the resize, it's ok for me the "uncompressed" parameter is interesting only if we have to choose between good quality of images or good performance

    点赞 评论 复制链接分享
  • weixin_39610488 weixin_39610488 5月前

    Ok, the uncompress option is available.

    You can pass an optional parameter like this:

     js
    map.toDataURL({
      uncompress: true
    }, function(image) {
       ...
    });
    

    If you omit the optional parameter, the plugin return compress (resized) image.

    点赞 评论 复制链接分享
  • weixin_39854681 weixin_39854681 5月前

    Thanks guys, had issues with master so grabbed the code from the fix.

    点赞 评论 复制链接分享
  • weixin_39717865 weixin_39717865 5月前

    You could provide me a PR, I would merge it into main branch

    点赞 评论 复制链接分享
  • weixin_39942400 weixin_39942400 5月前

    if I get it well, you remove a resizing step do you think it can have a positive/negative impact on performance?

    点赞 评论 复制链接分享
  • weixin_39895881 weixin_39895881 5月前

    PR https://github.com/mapsplugin/cordova-plugin-googlemaps/pull/861. It would be awesome if you could make a new version including this change.

    Yes that is the only change I did. Creating the image from the canvas will be slightly faster, however, showing the image in the UI might be slightly slower because it has more pixel. Thus, its effect on performance should be negligible.

    点赞 评论 复制链接分享
  • weixin_39717865 weixin_39717865 5月前

    I'm thinking about a parameter. Instead of making this BC (we don't know how people currently handling the output), we should provide a new method or a parameter (like uncompressed=true) or (original=true)

    点赞 评论 复制链接分享
  • weixin_39895881 weixin_39895881 5月前

    Same thing happens on iOS. It can be fixed by replacing

    
    UIGraphicsBeginImageContext(self.mapCtrl.view.frame.size);
    

    with

    
    UIGraphicsBeginImageContextWithOptions(self.mapCtrl.view.frame.size, NO, 0.0f);
    

    in the method toDataURL in "Map.m".

    点赞 评论 复制链接分享
  • weixin_39942400 weixin_39942400 5月前

    hi
    interested in this feature could you provide a PR both for iOS and Android, that works with a parameter "uncompressed" as suggested by ?

    thanks !

    点赞 评论 复制链接分享
  • weixin_39895881 weixin_39895881 5月前

    Unfortunately, I do not have time for this at the moment. But I guess, this would only be a small change that should be easily doable.

    点赞 评论 复制链接分享
  • weixin_39610488 weixin_39610488 5月前

    I have been checking all issues that are currently filed one by one. Thus, I will check this later. Hold on please.

    点赞 评论 复制链接分享
  • weixin_39610488 weixin_39610488 5月前

    Do you guys really want to uncompress parameter?

    点赞 评论 复制链接分享

相关推荐