简体   繁体   English

实际图像大小如何处理颤振?

[英]How the actual image size work on flutter?

In the following image my phone screen size is (1080x1920) and the image (a red square) showing on the screen is (400x400) pixels.在下图中,我的手机屏幕尺寸为 (1080x1920),屏幕上显示的图像(红色方块)为 (400x400) 像素。 But the image occupy large space more than 400px on the device screen.但是图像在设备屏幕上占据了超过 400px 的大空间。 Why flutter show in such way?为什么flutter显示这样? Doesn't flutter care about actual image pixel?颤振不关心实际图像像素吗?

As far as I know, in normal (Java) android app it take place only the image size (if image size is 72 then showing 72x72 pixels) on the screen, if we need large image for high-res screens, it needs to create the same image with larger size.据我所知,在普通(Java)android 应用程序中,它只在屏幕上显示图像大小(如果图像大小为 72,则显示 72x72 像素),如果我们需要高分辨率屏幕的大图像,则需要创建具有更大尺寸的相同图像。

在此处输入图片说明

Following is the dart code.以下是飞镖代码。

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Image align test',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Image align test'),
        ),
        body: Container(child: Image.asset('images/pic1.png')),
      ),
    );
  }
}

How the image is sized is determined by the BoxFit.图像的大小由 BoxFit 决定。 The Widget itself takes as much space as possible. Widget 本身占用尽可能多的空间。 You can supply that to the image (eg Image.asset('images/pic1.png',fit: BoxFit.cover) . The whole enum is found here , but the one you expect is probably Boxfit.none:您可以将其提供给图像(例如Image.asset('images/pic1.png',fit: BoxFit.cover) 。整个枚举可以在这里找到,但您期望的可能是 Boxfit.none:

Boxfit.none

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM