add getBitmap to NativeImage

This commit is contained in:
Heilig Benedek 2016-08-04 19:36:01 +02:00 committed by Cheng Zhao
parent 736fbd46c6
commit 37f5ef5712
2 changed files with 14 additions and 0 deletions

View file

@ -228,6 +228,18 @@ v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
bitmap->getSafeSize()).ToLocalChecked(); bitmap->getSafeSize()).ToLocalChecked();
} }
void noop(char*, void*) {}
v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
const SkBitmap* bitmap = image_.ToSkBitmap();
SkPixelRef* ref = bitmap->pixelRef();
return node::Buffer::New(isolate,
reinterpret_cast<char*>(ref->pixels()),
bitmap->getSafeSize(),
&noop,
nullptr).ToLocalChecked();
}
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
std::vector<unsigned char> output; std::vector<unsigned char> output;
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
@ -361,6 +373,7 @@ void NativeImage::BuildPrototype(
.SetMethod("toPNG", &NativeImage::ToPNG) .SetMethod("toPNG", &NativeImage::ToPNG)
.SetMethod("toJPEG", &NativeImage::ToJPEG) .SetMethod("toJPEG", &NativeImage::ToJPEG)
.SetMethod("toBitmap", &NativeImage::ToBitmap) .SetMethod("toBitmap", &NativeImage::ToBitmap)
.SetMethod("getBitmap", &NativeImage::GetBitmap)
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle) .SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
.SetMethod("toDataURL", &NativeImage::ToDataURL) .SetMethod("toDataURL", &NativeImage::ToDataURL)
.SetMethod("isEmpty", &NativeImage::IsEmpty) .SetMethod("isEmpty", &NativeImage::IsEmpty)

View file

@ -71,6 +71,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate); v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality); v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
v8::Local<v8::Value> ToBitmap(v8::Isolate* isolate); v8::Local<v8::Value> ToBitmap(v8::Isolate* isolate);
v8::Local<v8::Value> GetBitmap(v8::Isolate* isolate);
v8::Local<v8::Value> GetNativeHandle( v8::Local<v8::Value> GetNativeHandle(
v8::Isolate* isolate, v8::Isolate* isolate,
mate::Arguments* args); mate::Arguments* args);