Support toPNG on image without 1x representation
This commit is contained in:
parent
8bc65ef495
commit
c11cdf321b
1 changed files with 11 additions and 4 deletions
|
@ -231,10 +231,17 @@ HICON NativeImage::GetHICON(int size) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
||||||
scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
|
if (HasRepresentation(1.0)) {
|
||||||
return node::Buffer::Copy(isolate,
|
scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
|
||||||
reinterpret_cast<const char*>(png->front()),
|
const char* data = reinterpret_cast<const char*>(png->front());
|
||||||
static_cast<size_t>(png->size())).ToLocalChecked();
|
const size_t length = static_cast<size_t>(png->size());
|
||||||
|
return node::Buffer::Copy(isolate, data, length).ToLocalChecked();
|
||||||
|
} else {
|
||||||
|
std::vector<unsigned char> encoded;
|
||||||
|
gfx::PNGCodec::EncodeBGRASkBitmap(image_.AsBitmap(), false, &encoded);
|
||||||
|
const char* data = reinterpret_cast<char*>(encoded.data());
|
||||||
|
return node::Buffer::Copy(isolate, data, encoded.size()).ToLocalChecked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue