how to resize the screenshot of Android using adbkit?

Viewed 182

I use client.screencap method from adbkit to get the PNG stream and save the image like this:

 let stream = await client.screencap(deviceId);

 stream.pipe(fs.createWriteStream('output.png'));

Rather, I want to resize it first because the output image is so big ( around 2 - 3 Mb ). So I try to get the buffer of the stream and resize it by reducing width, height (use Jimp library) and save the image.

 let stream = await client.screencap(deviceId);
 let chunks = [];
 for await (const chunk of stream) {
    chunks.push(chunk);
 }
 let buffer = Buffer.concat(chunks);

 console.log(buffer);

 // resize and save (Use Jimp library to read the buffer and resize)
 ...

in console.log(buffer), I got

<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 00 00 01 73 ae ce 1c e9 00 00 00 04 ... 159002 more bytes>

But sometime I got empty buffer like this:

<Buffer >

I don't know why the buffer is empty. Because of client.screencap method is not stable?

Or they are an any better solution to do a thing like this?

0 Answers
Related