Jump to content
  • 0

html5 canvas проблемы с putImageData


iillyyaa2
 Share

Question

проблема с putImageData или чем то ещё, но данные "бьются"


<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /><title>.</title></head>
<body>
<canvas id="myCanvas2" width="4" height="4"></canvas>
<div id='divid'></div>
<script>
var canvas2=document.getElementById('myCanvas2'); var img2=canvas2.getContext('2d');
var arD=[1,2,3,4,5,6,7,8,100,100,100,100,200,200,200,200,255,255,255,255,100,0,0,0,200,200,200,0,0,0,0,255];
var arD2=[];
function calcImg(){
var x;
var ar = img2.getImageData(0,0,4,4);
for (x=0;x<arD.length;x++) {
ar.data[x]=arD[x];
}
img2.putImageData(ar, 0, 0);
var ar2 = img2.getImageData(0,0,4,4);
for (x=0;x<arD.length;x++) {
arD2[arD2.length]=ar2.data[x];
}
for (x=0;x<arD.length;x+=4) {
document.getElementById('divid').innerHTML += '<br>'+arD[x]+','+arD[x+1]+','+arD[x+2]+','+arD[x+3];
}
document.getElementById('divid').innerHTML += '<br>';
for (x=0;x<arD.length;x+=4) {
document.getElementById('divid').innerHTML += '<br>'+arD2[x]+','+arD2[x+1]+','+arD2[x+2]+','+arD2[x+3];
}
};
calcImg();
</script>
</body>
</html>

имели:

1,2,3,4

5,6,7,8

100,100,100,100

200,200,200,200

255,255,255,255

100,0,0,0

200,200,200,0

0,0,0,255

получили:

63,63,63,4

31,31,31,8

102,102,102,100

200,200,200,200

255,255,255,255

0,0,0,0

0,0,0,0

0,0,0,255

есть ли решение?

Edited by iillyyaa2
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy