Use Buffer.from, as in:

...
var imgData = ctx.getImageData(0,0,250,300);
var data = imgData.data;
var buf = Buffer.from(data);
Answer from logidelic on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8ClampedArray › Uint8ClampedArray
Uint8ClampedArray() constructor - JavaScript - MDN Web Docs
July 10, 2025 - // From a length const uint8c = new Uint8ClampedArray(2); uint8c[0] = 42; uint8c[1] = 1337; console.log(uint8c[0]); // 42 console.log(uint8c[1]); // 255 (clamped) console.log(uint8c.length); // 2 console.log(uint8c.BYTES_PER_ELEMENT); // 1 // From an array const x = new Uint8ClampedArray([21, 31]); console.log(x[1]); // 31 // From another TypedArray const y = new Uint8ClampedArray(x); console.log(y[0]); // 21 // From an ArrayBuffer const buffer = new ArrayBuffer(8); const z = new Uint8ClampedArray(buffer, 1, 4); console.log(z.byteOffset); // 1 // From an iterable const iterable = (function* () { yield* [1, 2, 3]; })(); const uint8cFromIterable = new Uint8ClampedArray(iterable); console.log(uint8cFromIterable); // Uint8ClampedArray [1, 2, 3] Polyfill of Uint8ClampedArray in core-js · JavaScript typed arrays guide · TypedArray · ArrayBuffer · DataView · Was this page helpful to you?
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Uint8ClampedArray
Uint8ClampedArray - JavaScript - MDN Web Docs
July 10, 2025 - The Uint8ClampedArray typed array represents an array of 8-bit unsigned integers clamped to 0–255. The contents are initialized to 0 unless initialization data is explicitly provided. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
🌐
JavaScripture
javascripture.com › Uint8ClampedArray
Uint8ClampedArray JavaScript API
Gets and sets the element in this at index. index should be between 0 and this.length - 1. Setting an element to a value less than 0 will store 0 and greater than 255 will store 255 in the array. ... Returns the underlying buffer for this Uint8ClampedArray.
🌐
Stack Overflow
stackoverflow.com › questions › 50545135 › why-is-conversion-from-an-untyped-array-to-uint8clampedarray-so-slow › 52192816
Why is conversion from an untyped array to Uint8ClampedArray so slow?
May 26, 2018 - Doing so, like this: outputBufferRaw = pixelateMatrix(frameBuffer); // shading = ~30ms (kinda slow) outputBuffer = new Uint8ClampedArray(outputBufferRaw); // conversion = ~100ms (very slow) takes ~100ms, far far too slow for a real time rendering ...
🌐
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › uint8clampedarray
Uint8ClampedArray - JavaScript | MDN
February 18, 2022 - Returns the length (in bytes) of the Uint8ClampedArray from the start of its ArrayBuffer.
Find elsewhere
🌐
GitHub
github.com › lovell › sharp › issues › 549
Pipe buffer image data into Uint8ClampedArray format · Issue #549 · lovell/sharp
August 22, 2016 - I've tried a ton of things and the only process that actually shows me an array is buffer.toJSON().data. Looking at that the numbers are all at or below 255, however I can't see any every fourth number is 255 pattern which indicates something is wrong. ... How can I get an Uint8ClampedArray with the proper [r1, g1, b1, a1, r2, g2, b2, a2.....] formatting from the image buffer in node that I can then pass to my function?
Author: lovell
🌐
MDN
mdn2.netlify.app › en-us › docs › web › javascript › reference › global_objects › uint8clampedarray › uint8clampedarray
Uint8ClampedArray() constructor - JavaScript | MDN
February 18, 2022 - // From a length var uintc8 = new ... console.log(y[0]); // 21 // From an ArrayBuffer var buffer = new ArrayBuffer(8); var z = new Uint8ClampedArray(buffer, 1, 4); // From an iterable var iterable = function*(){ yield* [1,2,3]; ...
🌐
Salesforce
documentation.b2c.commercecloud.salesforce.com › DOC3 › topic › com.demandware.dochelp › DWAPI › scriptapi › html › api › class_TopLevel_Uint8ClampedArray.html
Class Uint8ClampedArray | Salesforce B2C Developer Documentation Resources
The start offset for this typed array within the array buffer. ... The number of elements. ... Creates an empty array. ... Creates an array with the given element count. ... Creates an array as a copy of the passed typed array. ... Creates an array as a copy of the passed array. Uint8ClampedArray(buffer : ArrayBuffer, byteOffset : Number, length : Number)
🌐
Stack Overflow
stackoverflow.com › questions › 39087314 › pipe-buffer-image-data-into-uint8clampedarray-format-in-node-js
Pipe buffer image data into Uint8ClampedArray format in Node.js
August 24, 2018 - The .data property of the ImageData object appears to be a Uint8ClampedArray that reads [r1, g1, b1, a1, r2, g2, b2, a2.....] Looking at the pattern, every fourth number is 255 which makes sense as none of the image is transparent at all. I am trying to get this to work in Node.js in a similar fashion, except I'm getting my image data from a buffer generated by https://github.com/lovell/sharp:
🌐
Google Groups
groups.google.com › g › emscripten-discuss › c › -Ac-XNpVIL8
Converting a memory location to an ArrayBuffer
November 11, 2016 - var dim = 1080; var buffer = Module.createBitmap(dim); var c = document.getElementById("bitmap"); var ctx = c.getContext("2d"); var imgData = ctx.createImageData(dim,dim); for (var i = 0; i < dim*dim*4; i++) { imgData.data[i] = Module.HEAPU8[buffer+i]; } ctx.putImageData(imgData, 0, 0) What I don't like here though is the fact that I have to loop through all the bitmap components separately and assign them to the imgData.data array. This array is a Uint8ClampedArray and I was wondering if there is a way to convert this 'buffer' variable to an ArrayBuffer of type Uint8ClampedArray which would save a lot of copying.
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › global_objects › uint8clampedarray › uint8clampedarray › index.md
content/files/en-us/web/javascript/reference/global_objects/uint8clampedarray/uint8clampedarray/index.md at main · mdn/content
new Uint8ClampedArray(buffer) new Uint8ClampedArray(buffer, byteOffset) new Uint8ClampedArray(buffer, byteOffset, length) ``` · > [!NOTE] > `Uint8ClampedArray()` can only be constructed with [`new`](/en-US/docs/Web/JavaScript/Reference/Operators/new). Attempting to call it without `new` throws a {{jsxref("TypeError")}}. ·
Author: mdn
🌐
W3cubDocs
docs.w3cub.com › javascript › global_objects › uint8clampedarray
Uint8ClampedArray - JavaScript - W3cubDocs
August 7, 2022 - Returns a number value of the element size. 1 in the case of a Uint8ClampedArray.
🌐
GitHub
github.com › lovell › sharp › issues › 1868
Is there a way to get an "Uint8ClampedArray" and create a sharp from it? · Issue #1868 · lovell/sharp
September 12, 2019 - I'm trying to do some transformations to get a Uint8ClampedArray since I need it to run blurhash on it, a blur library you can find here, but to get the Uint8ClampedArray I need to run some transformation from the UInt8Array that I get from running .raw() function.
Author: lovell
🌐
Edgecompute
js-compute-reference-docs.edgecompute.app › uint8clampedarray
Uint8ClampedArray | @fastly/js-compute
The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation). new Uint8ClampedArray() new Uint8ClampedArray(length) new Uint8ClampedArray(typedArray) new Uint8ClampedArray(object) new Uint8ClampedArray(buffer) new Uint8ClampedArray(buffer, byteOffset) new Uint8ClampedArray(buffer, byteOffset, length) Note: Uint8ClampedArray() can only be constructed with new.
🌐
npm
npmjs.com › search
keywords:Uint8ClampedArray - npm search
IPC shared memory for NodeJs. Use as Buffer or TypedArray.