简体   繁体   English

如果浏览器缩小大图像,它会在不同的屏幕分辨率上显示相同数量的细节吗?

[英]If the browser downscales a large image, will it display the same amount of detail on different screen resolutions?

This question relates to web development.这个问题与 web 开发有关。

I'm going to start by apologizing for the horrible title but I wasn't sure how to title this.我将首先为这个可怕的标题道歉,但我不知道如何命名。 CSS pixels and how they interact with screen resolutions confuse me a bit already, when you add "intermediate pixel layers" and image drawing it's even more nebulous. CSS 像素以及它们如何与屏幕分辨率交互已经让我有点困惑,当您添加“中间像素层”和图像绘制时,它更加模糊。 So here's my actual question:所以这是我的实际问题:

Let's say that we have an image set to display as 2x1 (css pixels) on a web page.假设我们有一个图像设置为在 web 页面上显示为2x1 (css 像素)。 And we instead feed it a 4x1 image (rasterized).我们改为提供4x1图像(光栅化)。 The browser will fit this image to the 2x1 css pixels we specified earlier.浏览器会将此图像适合我们之前指定的2x1 css 像素。 But, would we technically be able to see all 4x1 pixels on a setup where 1 CSS pixels = 2 device pixels ?但是,从技术上讲,我们是否能够在1 CSS 像素 = 2 设备像素的设置中看到所有4x1像素? Or would it instead resize the 4x1 image to 2x1 then display each pixel twice?或者它会将4x1图像的大小调整为2x1 ,然后将每个像素显示两次? And does this change on a per browser/device basis?这会根据每个浏览器/设备而改变吗?

Bonus points: How does this play into accessibility tools that zoom into web content for the visually impaired?加分项:这对可放大视障人士的 web 内容的辅助工具有何影响? (if at all). (如果有的话)。

Answering my own question.回答我自己的问题。 The short answer is YES browsers will show different amounts of detail based on screen resolution.简短的回答是的,浏览器会根据屏幕分辨率显示不同数量的细节。

CSS pixels ARE NOT screen pixels. CSS 像素不是屏幕像素。 If an image is 600x600 pixels and you decide to display it in a CSS-defined area of 300x300 ( img:{width:300px;height:300px} ), it could display as 300x300 screen pixels or it could display as 600x600 screen pixels.如果图像为 600x600 像素,并且您决定将其显示在 CSS 定义的 300x300 ( img:{width:300px;height:300px} ) 区域中,则它可以显示为 300x300 屏幕像素,也可以显示为 600x600 屏幕像素。 Which of the two it is will depend on the end user's OS screen resolution.两者中的哪一个将取决于最终用户的操作系统屏幕分辨率。

Example :示例

I created a 4x1 pixel png image:我创建了一个 4x1 像素的 png 图像:

4 x 1 像素图像

I added this image to an html page and sized it with a img:{width:2px; height:1px;}我将此图像添加到 html 页面并使用img:{width:2px; height:1px;} img:{width:2px; height:1px;} . img:{width:2px; height:1px;} For good measure, I also added a blue div with div:{width:2px; height:1px;}为了更好的衡量,我还添加了一个蓝色 div div:{width:2px; height:1px;} div:{width:2px; height:1px;} bellow it. div:{width:2px; height:1px;}下面。

I then set the "css resolution" of the page to half that of my OS screen resolution (If the OS was set to 2000x2000 I made sure that the full html page had a css widthxheight of 1000x1000px).然后我将页面的“css 分辨率”设置为我的操作系统屏幕分辨率的一半(如果操作系统设置为 2000x2000,我确保整个 html 页面的 css 宽度x高度为 1000x1000px)。 So each css pixel would contain 4 screen pixels.所以每个 css 像素将包含 4 个屏幕像素。

This is how it displayed:这是它的显示方式:

在此处输入图像描述

Both the image and the blue div are 2px wide (that's css pixels) but they display as 4 screen pixels.图像和蓝色 div 都是 2px 宽(即 css 像素),但它们显示为 4 个屏幕像素。 In the case of the blue div, it duplicates the pixels to fit the screen resolution.对于蓝色 div,它会复制像素以适应屏幕分辨率。 But in the case of the image, it displays all 4 individual pixels.但在图像的情况下,它显示所有 4 个单独的像素。 In both cases, it duplicates the pixels vertically to fit the screen resolution (technically it's probably more of a stretch than a duplication, but you get the idea).在这两种情况下,它都会垂直复制像素以适应屏幕分辨率(从技术上讲,它可能更像是拉伸而不是复制,但你明白了)。

I'm not entirely sure about this but I'm assuming at this stage that all browsers act in a similar fashion.我对此并不完全确定,但我假设在这个阶段所有浏览器都以类似的方式运行。

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

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