使用下面的代碼,我想結束:
- 一個 400x400 的相機捕捉
- 400x400 畫布
- 400x400 的影像
let capture
let universalWidth = 400
let testImg = undefined
function setup() {
testImg = document.getElementById('test')
capture = createCapture({
audio: false,
video: {
width: universalWidth,
height: universalWidth
}
})
capture.size(universalWidth, universalWidth)
createCanvas(universalWidth, universalWidth)
}
function draw() {
image(capture.get(), 0, 0)
testImg.src = canvas.toDataURL()
}
相反,我最終得到的是:
- 一個 400x400 的相機捕捉
- 一個 400x400 的畫布,其
width和height屬性設定為800 - 一張 800x800 的圖片
我該如何解決 ?
您可以在此處查看實際問題
uj5u.com熱心網友回復:
畫布的寬度和高度屬性設定為 800,因為您在高 DPI(即 Apple Retina)顯示幕上運行此草圖。當 p5.js 檢測到這一點時,它默認將像素密度設定為 2,因此它會采用 800 像素的正方形圖形并將其壓縮成螢屏上的 400“像素”正方形。如果你想要一個影像,這正是400的實際像素,可以像素密度設定為1你的setup()功能:pixelDensity(1)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/355037.html
標籤:javascript 图像处理 帆布 p5.js
