зеркало из https://github.com/electron/electron.git
Cleanup the code of getBitmap
This commit is contained in:
Родитель
b5c19a9c6d
Коммит
1be253e1aa
|
@ -172,6 +172,9 @@ bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void Noop(char*, void*) {
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
|
||||
|
@ -228,18 +231,6 @@ v8::Local<v8::Value> NativeImage::ToBitmap(v8::Isolate* isolate) {
|
|||
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) {
|
||||
std::vector<unsigned char> output;
|
||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||
|
@ -258,6 +249,16 @@ std::string NativeImage::ToDataURL() {
|
|||
return data_url;
|
||||
}
|
||||
|
||||
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::GetNativeHandle(v8::Isolate* isolate,
|
||||
mate::Arguments* args) {
|
||||
#if defined(OS_MACOSX)
|
||||
|
|
|
@ -163,7 +163,8 @@ Returns a [Buffer][buffer] that contains the image's `JPEG` encoded data.
|
|||
|
||||
#### `image.toBitmap()`
|
||||
|
||||
Returns a [Buffer][buffer] that contains a copy of the image's raw pixel data.
|
||||
Returns a [Buffer][buffer] that contains a copy of the image's raw bitmap pixel
|
||||
data.
|
||||
|
||||
#### `image.toDataURL()`
|
||||
|
||||
|
@ -171,8 +172,11 @@ Returns the data URL of the image.
|
|||
|
||||
#### `image.getBitmap()`
|
||||
|
||||
Returns a [Buffer][buffer] that contains the image's raw pixel data. The pixel
|
||||
data is not owned by the `Buffer` object.
|
||||
Returns a [Buffer][buffer] that contains the image's raw bitmap pixel data.
|
||||
|
||||
The difference between `getBitmap()` and `toBitmap()` is, `getBitmap()` does not
|
||||
copy the bitmap data, so you have to use the returned Buffer immediately in
|
||||
current event loop tick, otherwise the data might be changed or destroyed.
|
||||
|
||||
#### `image.getNativeHandle()` _macOS_
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче