save Graphics buffer and reuse

Posted on
  • I want to preserve the content of Graphics buffer and reuse it later. But when I store in a new Uint8Array it and call graphics.clear(), it clears the saved variable also. See below example.

    I am saving g.buffer in fb variable and after calling g.clear(), it clears fb also.

    How to resolve this?

    >g=Graphics.createArrayBuffer(8,8,8);
    =Graphics: {
      buffer: new ArrayBuffer(64)
     }
    >g.drawLine(0,0,7,7)
    =Graphics: {
      buffer: new Uint8Array([255, 0, 0, 0, 0,  ... 0, 0, 0, 0, 255]).buffer
     }
    >var fb = (new Uint8Array(g.buffer))
    =new Uint8Array([255, 0, 0, 0, 0,  ... 0, 0, 0, 0, 255])
    >print(fb);
    new Uint8Array([255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255])
    =undefined
    >g.clear();
    =Graphics: {
      buffer: new ArrayBuffer(64)
     }
    >print(fb)
    new Uint8Array(64)
    =undefined
    
  • I found answer here

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

save Graphics buffer and reuse

Posted by Avatar for Abhigkar @Abhigkar

Actions