| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../../../resources/js-test.js"></script> | |
| 3 <script> | |
| 4 jsTestIsAsync = true; | |
| 5 | |
| 6 description("Tests that createImageBitmap from a canvas.toBlob object should hav
e the same pixel data as the blob."); | |
| 7 | |
| 8 var imageData2; | |
| 9 var imageData3; | |
| 10 | |
| 11 var canvas1 = document.createElement("canvas"); | |
| 12 var ctx1 = canvas1.getContext("2d"); | |
| 13 ctx1.fillStyle = "#FF0000"; | |
| 14 ctx1.fillRect(0, 0, 150, 75); | |
| 15 | |
| 16 var newImg = new Image(); | |
| 17 newImg.onload = function() { | |
| 18 var canvas3 = document.createElement("canvas"); | |
| 19 var ctx3 = canvas3.getContext("2d"); | |
| 20 ctx3.drawImage(newImg, 0, 0, 150, 75); | |
| 21 | |
| 22 imageData3 = ctx3.getImageData(0, 0, 150, 75).data; | |
| 23 var imageMatched = true; | |
| 24 for (var i = 1; i < imageData2.length; i++) { | |
| 25 if (imageData2[i] != imageData3[i]) { | |
| 26 imageMatched = false; | |
| 27 break; | |
| 28 } | |
| 29 } | |
| 30 if (imageMatched) | |
| 31 testPassed("image data from the created ImageBitmap and the originated b
lob is the same"); | |
| 32 else | |
| 33 testFailed("image data from the created ImageBitmap and the originated b
lob is NOT the same"); | |
| 34 finishJSTest(); | |
| 35 } | |
| 36 | |
| 37 canvas1.toBlob(function(blob) { | |
| 38 createImageBitmap(blob).then(imageBitmap => { | |
| 39 var canvas2 = document.createElement("canvas"); | |
| 40 var ctx2 = canvas2.getContext("2d"); | |
| 41 ctx2.drawImage(imageBitmap, 0, 0, 150, 75); | |
| 42 imageData2 = ctx2.getImageData(0, 0, 150, 75).data; | |
| 43 url = URL.createObjectURL(blob); | |
| 44 newImg.src = url; | |
| 45 }); | |
| 46 }); | |
| 47 </script> | |
| OLD | NEW |