Device pixel ratio without the BuildContext


I need to make resolution resolution-aware images (BitmapDescriptor)

static Future<BitmapDescriptor> makeBitmapDescriptor(
      String path, BuildContext context) {
    return BitmapDescriptor.fromAssetImage(
      ImageConfiguration(devicePixelRatio: MediaQuery.of(context).devicePixelRatio,

& for that I need the devicePixelRatio, is there a way to get it without the BuildContext & MediaQuery.of(context).devicePixelRatio ?


You can use fromWindow like this:


Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at


Login to comment


what exactly is device pixel ratio?

How to calculate device pixel ratio

Font-size and device-pixel-ratio

Understanding responsive images and device pixel ratio

What is the view port width, height and device pixel ratio for the devices Google Pixel and Google Pixel XL

Retina - Correlation between device pixel ratio and size of image?

Where I can find the Pixel Ratio of the device detail?

-webkit-min-device-pixel-ratio gives a CSS validation error

Responsive Design: max-device-width, max-width and min-device-pixel-ratio

Preload Image Without BuildContext

Mozilla firefox using "@media screen and (-webkit-min-device-pixel-ratio:0)"

Why this 100% width image is bigger than screen width * device pixel ratio

How to display a specific size image using SRCSET no matter what the device's pixel ratio is?

Firefox 63 Webkit CSS issue using device pixel ratio media query

ImageMagick: Determining Pixel Aspect Ratio

Invalid pixel aspect ratio in ffmpeg

Getting screen size in a class without buildcontext in Flutter

dirty_ratio per device

calculate the pixel ratio of two halves of an image

using <ratio> without typedef

How to change the dimensions of the Jssor Image Slider without losing it's responsive nature, image aspect ratio, etc. only on iPhone device?

Pixel Overflow on Android Device - Flutter

Create a Pixel 4 Virtual Device

How can I get the screen size in Flutter without BuildContext?

How to get context in a simple class without BuildContext in flutter

How to display Dialog in Flutter without a Buildcontext inside a HookWidget

How to keep the aspect ratio when changing device?

React Native Android get device's ratio

SVG pixel ratio is 1:2 from code to rendering

TOP Ranking