Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
How to convert 16bit raw data into png image to show in browser?

I have 16 bit raw data as base64 string. Want to convert that into png image, based on depth 8,16,24.

// code to process 16bit buffer array
function process16bitBitmap(buffer, options = {}) {
const view = new Uint8ClampedArray(buffer);
const out = new Uint8ClampedArray(buffer.byteLength);
// set alpha channel
view.forEach((a, i) => out[(i * 4) + 3] = a);
const canvas = document.createElement('canvas');
canvas.width = options.width;
canvas.height = options.height;
const imgData = new ImageData(out, options.width, options.height);
canvas.getContext('2d').putImageData(imgData, 0, 0);
// if you want to save a png version
document.body.appendChild(canvas);}

fiddle to reproduce the issue jsfiddle

Facing hard time to correctly create a png file from 16 bit raw data. 16 bit image should looks like this.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

With javaScript Vanilla:

I found this but coundn't find a way to reproduce.

With nodejs:

I found this and it works fine. Also found this but didn't work for me.

const fs = require('fs');
const path = require('path');

const base64ToPNG = (data) => {
    data = data.replace(/^data:image\/png;base64,/, '');

    fs.writeFile(path.resolve(__dirname, 'image.png'), data, 'base64', function (err) {
        if (err) throw err;
    });
}

var img = "YourImageHere...iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAAAbWs+...";

base64ToPNG(img)

If your objective is doing it with vanilla I don't know if I could help you, with node that way works, so probably you'll just need to figure how to adjust the depth.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!