HTML canvas putImageData() နည်းလမ်း
ဥပမာ
အောက်ပါကုဒ်သည် getImageData() ဖြင့် ကင်းဗတ်ပေါ်တွင် သတ်မှတ်ထားသော ထောင့်မှန်စတုဂံတစ်ခုအတွက် pixel ဒေတာကို မိတ္တူကူးပြီး ပုံဒေတာကို putImageData() ဖြင့် ကင်းဗတ်ပေါ်သို့ ပြန်တင်ပါ။
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 50, 50);
function copy()
{
var imgData = ctx.getImageData(10, 10, 50, 50);
ctx.putImageData(imgData, 10, 70);
}
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
putImageData() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
putImageData() နည်းလမ်းသည် ပုံဒေတာ (သတ်မှတ်ထားသော ImageData အရာဝတ္ထုမှ) ကို ကင်းဗတ်စ်ပေါ်သို့ ပြန်တင်သည်။
အကြံပြုချက်- ကင်းဗတ်စ်ပေါ်တွင် သတ်မှတ်ထားသော စတုဂံတစ်ခုအတွက် pixel ဒေတာကို ကူးယူသည့် getImageData() နည်းလမ်း အကြောင်း ဖတ်ပါ ။
အကြံပြုချက်- အလွတ် ImageData အရာဝတ္ထုအသစ်ကို ဖန်တီးသည့် createImageData () နည်းလမ်း အကြောင်း ဖတ်ပါ ။
JavaScript Syntax
JavaScript syntax- | ဆက်စပ်အကြောင်းအရာ .putImageData( imgData၊ x၊ y၊ dirtyX၊ dirtyY၊ dirtyWidth၊ dirtyHeight ); |
---|
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
imgData | Specifies the ImageData object to put back onto the canvas |
x | The x-coordinate, in pixels, of the upper-left corner of where to place the image on the canvas |
y | The y-coordinate, in pixels, of the upper-left corner of where to place the image on the canvas |
dirtyX | Optional. The x-coordinate, in pixels, of the upper-left corner of where to start drawing the image. Default 0 |
dirtyY | Optional. The y-coordinate, in pixels, of the upper-left corner of where to start drawing the image. Default 0 |
dirtyWidth | Optional. The width to use when drawing the image on the canvas. Default: the width of the extracted image |
dirtyHeight | Optional. The height to use when drawing the image on the canvas. Default: the height of the extracted image |
❮ Canvas Object