问题描述
toDataURL
:
Syntax
canvas.toDataURL(type, encoderOptions);
Parameters
type Optional
A DOMString indicating the image format. The default type is image/png.
encoderOptions Optional
A Number between 0 and 1 indicating image quality if the requested type is image/jpeg or image/webp.
If this argument is anything else, the default value for image quality is used. Other arguments are ignored.
如果此参数为其他参数,则使用图像质量的默认值。其他参数将被忽略。
。图像质量的默认值是什么?
If this argument is anything else, the default value for image quality is used. Other arguments are ignored.
. What's the default value for image quality?
推荐答案
闪烁:JPEG为0.92,WEBP为0.80。
Gecko:JPEG为0.92(无网页支持)
我是如何找到的
我使用
相关代码
看起来像这样设置质量 double quality = UndefinedQualityValue;
其中 UndefinedQualityValue;
是-1.0的常量。
Looks like it sets the quality like so double quality = UndefinedQualityValue;
where UndefinedQualityValue;
is a constant of -1.0.
在进一步向下调用链后,我们将进入
Following the call chain further down we get to https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp&sq=package:chromium&l=348&rcl=1448382621
bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
{
if (mimeType == "image/jpeg") {
int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
if (quality >= 0.0 && quality <= 1.0)
compressionQuality = static_cast<int>(quality * 100 + 0.5);
if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage))
return false;
} else if (mimeType == "image/webp") {
int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality;
if (quality >= 0.0 && quality <= 1.0)
compressionQuality = static_cast<int>(quality * 100 + 0.5);
if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage))
return false;
} else {
if (!PNGImageEncoder::encode(*this, encodedImage))
return false;
ASSERT(mimeType == "image/png");
}
return true;
}
其中值如下:
-
JPEGImageEncoder :: DefaultCompressionQuality = 92
-
WEBPImageEncoder :: DefaultCompressionQuality = 80
JPEGImageEncoder::DefaultCompressionQuality = 92
sourceWEBPImageEncoder::DefaultCompressionQuality = 80
source
我们可以通过mozilla代码搜索执行与上述类似的过程,或只是谷歌壁虎图像编码器,它将您带到以下值:
JPEG:0.92
We can follow a similar process as the above with mozilla code search, or just google "gecko image encoder" which takes you to the following value:JPEG: 0.92 source
这篇关于toDataURL中的默认图像质量是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!