Enable creating NativeImage from PNG and JPEG
This commit is contained in:
parent
53fca43d89
commit
85f5ef2ab1
2 changed files with 27 additions and 5 deletions
|
@ -66,11 +66,29 @@ gfx::Size NativeImage::GetSize() {
|
|||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
|
||||
const gfx::Image& image) {
|
||||
mate::Handle<NativeImage> NativeImage::Create(
|
||||
v8::Isolate* isolate, const gfx::Image& image) {
|
||||
return mate::CreateHandle(isolate, new NativeImage(image));
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromPNG(
|
||||
v8::Isolate* isolate, v8::Handle<v8::Value> buffer) {
|
||||
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(
|
||||
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
|
||||
node::Buffer::Length(buffer));
|
||||
return Create(isolate, image);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
|
||||
v8::Isolate* isolate, v8::Handle<v8::Value> buffer) {
|
||||
gfx::Image image = gfx::ImageFrom1xJPEGEncodedData(
|
||||
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
|
||||
node::Buffer::Length(buffer));
|
||||
return Create(isolate, image);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -19,11 +19,15 @@ namespace api {
|
|||
|
||||
class NativeImage : public mate::Wrappable {
|
||||
public:
|
||||
static mate::Handle<NativeImage> Create(v8::Isolate* isolate,
|
||||
const gfx::Image& image);
|
||||
static mate::Handle<NativeImage> Create(
|
||||
v8::Isolate* isolate, const gfx::Image& image);
|
||||
static mate::Handle<NativeImage> CreateFromPNG(
|
||||
v8::Isolate* isolate, v8::Handle<v8::Value> buffer);
|
||||
static mate::Handle<NativeImage> CreateFromJPEG(
|
||||
v8::Isolate* isolate, v8::Handle<v8::Value> buffer);
|
||||
|
||||
protected:
|
||||
NativeImage(const gfx::Image& image);
|
||||
explicit NativeImage(const gfx::Image& image);
|
||||
virtual ~NativeImage();
|
||||
|
||||
// mate::Wrappable:
|
||||
|
|
Loading…
Reference in a new issue