fix: nativeImage.crop().toBitmap() returning garbage (#25757)
This commit is contained in:
parent
a189dc779e
commit
485adae94c
2 changed files with 20 additions and 7 deletions
|
@ -183,13 +183,20 @@ v8::Local<v8::Value> NativeImage::ToBitmap(gin::Arguments* args) {
|
|||
|
||||
const SkBitmap bitmap =
|
||||
image_.AsImageSkia().GetRepresentation(scale_factor).GetBitmap();
|
||||
SkPixelRef* ref = bitmap.pixelRef();
|
||||
if (!ref)
|
||||
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
|
||||
return node::Buffer::Copy(args->isolate(),
|
||||
reinterpret_cast<const char*>(ref->pixels()),
|
||||
bitmap.computeByteSize())
|
||||
.ToLocalChecked();
|
||||
|
||||
SkImageInfo info =
|
||||
SkImageInfo::MakeN32Premul(bitmap.width(), bitmap.height());
|
||||
|
||||
auto array_buffer =
|
||||
v8::ArrayBuffer::New(args->isolate(), info.computeMinByteSize());
|
||||
auto backing_store = array_buffer->GetBackingStore();
|
||||
if (bitmap.readPixels(info, backing_store->Data(), info.minRowBytes(), 0,
|
||||
0)) {
|
||||
return node::Buffer::New(args->isolate(), array_buffer, 0,
|
||||
info.computeMinByteSize())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue