#endif
v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
- if (HasRepresentation(1.0)) {
- scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+ scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+ if (IsEmpty() || png->size() > 0) {
const char* data = reinterpret_cast<const char*>(png->front());
const size_t length = static_cast<size_t>(png->size());
return node::Buffer::Copy(isolate, data, length).ToLocalChecked();
}
std::string NativeImage::ToDataURL() {
- if (HasRepresentation(1.0)) {
- scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+ scoped_refptr<base::RefCountedMemory> png = image_.As1xPNGBytes();
+ if (IsEmpty() || png->size() > 0)
return webui::GetPngDataUrl(png->front(), png->size());
- } else {
+ else
return webui::GetBitmapDataUrl(image_.AsBitmap());
- }
}
v8::Local<v8::Value> NativeImage::GetBitmap(v8::Isolate* isolate) {
return image_.IsEmpty();
}
-bool NativeImage::HasRepresentation(float scale_factor) {
- return image_.AsImageSkia().HasRepresentation(scale_factor);
-}
-
gfx::Size NativeImage::GetSize() {
return image_.Size();
}
.SetMethod("resize", &NativeImage::Resize)
.SetMethod("crop", &NativeImage::Crop)
.SetMethod("getAspectRatio", &NativeImage::GetAspectRatio)
- .SetMethod("hasRepresentation", &NativeImage::HasRepresentation)
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
.SetMethod("toPng", &NativeImage::ToPNG)
.SetMethod("toJpeg", &NativeImage::ToJPEG);
it('returns an empty image', () => {
const empty = nativeImage.createEmpty()
assert.equal(empty.isEmpty(), true)
- assert.equal(empty.hasRepresentation(1.0), false)
assert.equal(empty.getAspectRatio(), 1)
assert.equal(empty.toDataURL(), 'data:image/png;base64,')
assert.deepEqual(empty.getSize(), {width: 0, height: 0})
scaleFactor: 2.0
})
assert.deepEqual(imageB.getSize(), {width: 269, height: 95})
- assert.equal(imageB.hasRepresentation(1.0), false)
- assert.equal(imageB.hasRepresentation(2.0), true)
const imageC = nativeImage.createFromDataURL(imageB.toDataURL())
assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
- assert.equal(imageC.hasRepresentation(1.0), false)
assert(imageB.toBitmap().equals(imageC.toBitmap()))
})
})
scaleFactor: 2.0
})
assert.deepEqual(imageB.getSize(), {width: 269, height: 95})
- assert.equal(imageB.hasRepresentation(1.0), false)
- assert.equal(imageB.hasRepresentation(2.0), true)
const imageC = nativeImage.createFromBuffer(imageB.toPNG())
assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
- assert.equal(imageC.hasRepresentation(1.0), true)
assert(imageB.toBitmap().equals(imageC.toBitmap()))
})
})