Merge pull request #4791 from atom/nativeimage-as-nsimage
Convert NativeImage instances to OS-specific representations
This commit is contained in:
commit
081ab17e13
4 changed files with 41 additions and 0 deletions
|
@ -184,6 +184,8 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
|
|||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("toPng", &NativeImage::ToPNG)
|
||||
.SetMethod("toJpeg", &NativeImage::ToJPEG)
|
||||
.SetMethod("getNativeHandle",
|
||||
&NativeImage::GetNativeHandle)
|
||||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||
.SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated.
|
||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||
|
@ -221,6 +223,23 @@ std::string NativeImage::ToDataURL() {
|
|||
return data_url;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(
|
||||
v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
void* ptr = NULL;
|
||||
#if defined(OS_MACOSX)
|
||||
ptr = reinterpret_cast<void*>(image_.AsNSImage());
|
||||
#else
|
||||
args->ThrowError();
|
||||
return v8::Undefined(isolate);
|
||||
#endif
|
||||
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
reinterpret_cast<char*>(ptr),
|
||||
sizeof(void*)).ToLocalChecked();
|
||||
}
|
||||
|
||||
bool NativeImage::IsEmpty() {
|
||||
return image_.IsEmpty();
|
||||
}
|
||||
|
|
|
@ -61,6 +61,9 @@ class NativeImage : public mate::Wrappable {
|
|||
private:
|
||||
v8::Local<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||
v8::Local<v8::Value> GetNativeHandle(
|
||||
v8::Isolate* isolate,
|
||||
mate::Arguments* args);
|
||||
std::string ToDataURL();
|
||||
bool IsEmpty();
|
||||
gfx::Size GetSize();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue