以下是toDataURL
的{{3}}:
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.
。图像质量的默认值是什么?
答案 0 :(得分:1)
我搜索了#34; toDataURL"使用https://code.google.com/p/chromium/codesearch
看起来它设置的质量如此double quality = UndefinedQualityValue;
,其中UndefinedQualityValue;
是-1.0的常量。
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
source WEBPImageEncoder::DefaultCompressionQuality = 80
source 我们可以按照与上述类似的流程进行mozilla代码搜索,或者只是google&#34; gecko image encoder&#34;它会将您带到以下值: JPEG:0.92 source