Enable converting gfx::Image to Buffer

This commit is contained in:
Cheng Zhao 2015-02-11 14:31:51 +08:00
parent ab315e502f
commit 878d25e91e
2 changed files with 15 additions and 3 deletions

View file

@ -16,10 +16,12 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#if !defined(OS_MACOSX) #include "atom/common/node_includes.h"
namespace mate { namespace mate {
#if !defined(OS_MACOSX)
namespace { namespace {
struct ScaleFactorPair { struct ScaleFactorPair {
@ -122,6 +124,14 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
return true; return true;
} }
} // namespace mate
#endif // !defined(OS_MACOSX) #endif // !defined(OS_MACOSX)
v8::Handle<v8::Value> Converter<gfx::Image>::ToV8(v8::Isolate* isolate,
const gfx::Image& val) {
scoped_refptr<base::RefCountedMemory> png = val.As1xPNGBytes();
return node::Buffer::New(isolate,
reinterpret_cast<const char*>(png->front()),
png->size());
}
} // namespace mate

View file

@ -26,6 +26,8 @@ struct Converter<gfx::Image> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
gfx::Image* out); gfx::Image* out);
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const gfx::Image& val);
}; };
} // namespace mate } // namespace mate