util.ts 983 B

1234567891011121314151617181920212223242526
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. export function debugTexture(imageData: ImageData, scale = 1) {
  7. const canvas = document.createElement('canvas')
  8. canvas.width = imageData.width
  9. canvas.height = imageData.height
  10. const ctx = canvas.getContext('2d')
  11. if (!ctx) throw new Error('Could not create canvas 2d context')
  12. ctx.putImageData(imageData, 0, 0)
  13. canvas.toBlob(imgBlob => {
  14. const objectURL = window.URL.createObjectURL(imgBlob)
  15. const img = document.createElement('img')
  16. img.src = objectURL
  17. img.style.width = imageData.width * scale + 'px'
  18. img.style.height = imageData.height * scale + 'px'
  19. img.style.position = 'absolute'
  20. img.style.top = '0px'
  21. img.style.left = '0px'
  22. img.style.border = 'solid grey'
  23. document.body.appendChild(img)
  24. }, 'image/png')
  25. }