Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Display screenshot in image

Discussion in 'Web' started by MrMatthias, Nov 4, 2020.

  1. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    I want to display a screenshot taken by ScreenCapture.CaptureScreenshot in a img element on the html page, but i don't know in what format it is saved in the indexed database and how to display that.
    I'm reading the screenshot out of the db and create a blob to show via a ObjectURL:
    Code (JavaScript):
    1. var transaction = db.transaction(["FILE_DATA"], IDBTransaction.READ_WRITE);
    2. transaction.objectStore("FILE_DATA").get("/idbfs/ef301f25d1b8e2bca70fafc1316f1a92/Screenshot").onsuccess = function (event) {
    3. var imgFile = event.target.result;
    4. var URL = window.URL || window.webkitURL;
    5. var blob = new Blob( imgFile.contents, { type: "image/png" } );
    6. var imgURL = URL.createObjectURL(blob);
    7. var img = document.getElementById("screenshot");
    8. img.setAttribute("src", imgURL);
    Opening the object url gives me this error message:
    Reading it from the db seems to work, it shows the correct timestamp, mode and contents length.

    In the indexeddb the screenshot looks like this:
     
  2. MrMatthias

    MrMatthias

    Joined:
    Sep 18, 2012
    Posts:
    191
    The issue was the blob object
    var blob = new Blob( imgFile.contents, { type: "image/png" } );

    should be
    var blob = new Blob( [imgFile.contents], { type: "image/png" } );
     
  3. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    279
    Last edited: Nov 5, 2020