moves bitmap parameters to options object

This commit is contained in:
gellert 2016-12-13 21:30:45 +01:00
parent 39875c90f1
commit a609e52a14
3 changed files with 16 additions and 10 deletions

View file

@ -408,14 +408,17 @@ mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
mate::Arguments* args, v8::Local<v8::Value> buffer) { mate::Arguments* args, v8::Local<v8::Value> buffer) {
int width = 0; int width = 0;
int height = 0; int height = 0;
if (args->Length() >= 3) {
args->GetNext(&width);
args->GetNext(&height);
}
double scale_factor = 1.; double scale_factor = 1.;
args->GetNext(&scale_factor); args->GetNext(&scale_factor);
mate::Dictionary options;
if (args->GetNext(&options)) {
options.Get("width", &width);
options.Get("height", &height);
options.Get("scaleFactor", &scale_factor);
}
gfx::ImageSkia image_skia; gfx::ImageSkia image_skia;
AddImageSkiaRep(&image_skia, AddImageSkiaRep(&image_skia,
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)), reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),

View file

@ -137,9 +137,11 @@ let image = nativeImage.createFromPath('/Users/somebody/images/icon.png')
console.log(image) console.log(image)
``` ```
### `nativeImage.createFromBuffer(buffer[width, height, scaleFactor])` ### `nativeImage.createFromBuffer(buffer[, scaleFactor, options])`
* `buffer` [Buffer][buffer] * `buffer` [Buffer][buffer]
* `scaleFactor` Double (optional)
* `options` Object (optional)
* `width` Integer (optional) * `width` Integer (optional)
* `height` Integer (optional) * `height` Integer (optional)
* `scaleFactor` Double (optional) * `scaleFactor` Double (optional)
@ -147,7 +149,7 @@ console.log(image)
Returns `NativeImage` Returns `NativeImage`
Creates a new `NativeImage` instance from `buffer`. The default `scaleFactor` is Creates a new `NativeImage` instance from `buffer`. The default `scaleFactor` is
1.0. If `buffer` is a bitmap, specify `width` and `height` of the image. 1.0. The `width` and `height` options are **required** for bitmap buffers.
### `nativeImage.createFromDataURL(dataURL)` ### `nativeImage.createFromDataURL(dataURL)`

View file

@ -26,7 +26,8 @@ describe('nativeImage module', () => {
const imageC = nativeImage.createFromBuffer(imageA.toJPEG(100)) const imageC = nativeImage.createFromBuffer(imageA.toJPEG(100))
assert.deepEqual(imageC.getSize(), {width: 538, height: 190}) assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
const imageD = nativeImage.createFromBuffer(imageA.toBitmap(), 538, 190) const imageD = nativeImage.createFromBuffer(imageA.toBitmap(),
{width: 538, height: 190})
assert.deepEqual(imageD.getSize(), {width: 538, height: 190}) assert.deepEqual(imageD.getSize(), {width: 538, height: 190})
}) })
}) })