Merge pull request #4836 from atom/get-native-handle-osx
Make it clear that image.getNativeHandle is OS X only
This commit is contained in:
commit
48f1eb4584
2 changed files with 15 additions and 16 deletions
|
@ -184,8 +184,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
|
|||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("toPng", &NativeImage::ToPNG)
|
||||
.SetMethod("toJpeg", &NativeImage::ToJPEG)
|
||||
.SetMethod("getNativeHandle",
|
||||
&NativeImage::GetNativeHandle)
|
||||
.SetMethod("getNativeHandle", &NativeImage::GetNativeHandle)
|
||||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||
.SetMethod("toDataUrl", &NativeImage::ToDataURL) // deprecated.
|
||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||
|
@ -223,21 +222,18 @@ std::string NativeImage::ToDataURL() {
|
|||
return data_url;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(
|
||||
v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
void* ptr = NULL;
|
||||
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
#if defined(OS_MACOSX)
|
||||
ptr = reinterpret_cast<void*>(image_.AsNSImage());
|
||||
NSImage* ptr = image_.AsNSImage();
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
reinterpret_cast<char*>(ptr),
|
||||
sizeof(void*)).ToLocalChecked();
|
||||
#else
|
||||
args->ThrowError();
|
||||
args->ThrowError("Not implemented");
|
||||
return v8::Undefined(isolate);
|
||||
#endif
|
||||
|
||||
return node::Buffer::Copy(
|
||||
isolate,
|
||||
reinterpret_cast<char*>(ptr),
|
||||
sizeof(void*)).ToLocalChecked();
|
||||
}
|
||||
|
||||
bool NativeImage::IsEmpty() {
|
||||
|
|
|
@ -133,11 +133,14 @@ Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data.
|
|||
|
||||
Returns the data URL of the image.
|
||||
|
||||
### `image.getNativeHandle()`
|
||||
### `image.getNativeHandle()` _OS X_
|
||||
|
||||
Returns a pointer to an underlying native type (encoded as a [Buffer][buffer]) which can be used with native APIs. Note that in many cases, this pointer is a weak pointer to the underlying native image not a copy, so you _must_ ensure that the associated `nativeImage` instance is kept around.
|
||||
Returns a [Buffer][buffer] that stores C pointer to underlying native handle of
|
||||
the image. On OS X, a pointer to `NSImage` instance would be returned.
|
||||
|
||||
Returns a [Buffer][buffer] that represents a pointer to a native type - on OS X, this type is an NSImage object.
|
||||
Notice that the returned pointer is a weak pointer to the underlying native
|
||||
image instead of a copy, so you _must_ ensure that the associated
|
||||
`nativeImage` instance is kept around.
|
||||
|
||||
### `image.isEmpty()`
|
||||
|
||||
|
|
Loading…
Reference in a new issue