justadudewhohacks / justadudewhohacks/opencv4nodejs

Issue with .imdecode(..), .getData(..) and Buffers

Open
#812 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
5.1k
Forks
826
PR merge metrics
No merged PRs in 30d

Description

Hello,

i would like to get image data loaded by **.imdecode(..)** method and write that data into image file,

so i used this code:

```
let c = cv.imdecode(data); // "data" is a **Buffer** variable
const imageBuffer = c.getData();
const buff = Buffer.from(imageBuffer);
let path = `uploads/${new Date().getTime()}.jpg`;
fs.writeFileSync(path, buff );
```
The code above created the image file, but it is corrupted (it displayed "failed to load image data" in explorer)..

after some researches, i tried this one too:

```
let c = cv.imdecode(data); // data is a **Buffer** variable
const imageBuffer = c.getData();
let ut8 = new Uint8Array(imageBuffer);
for (let i=0; i

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.