Add NativeImage.ToJPEG
This commit is contained in:
parent
549df36f00
commit
53fca43d89
2 changed files with 11 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
|||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/image/image_util.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
|
@ -32,6 +33,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
|
|||
if (template_.IsEmpty())
|
||||
template_.Reset(isolate, mate::ObjectTemplateBuilder(isolate)
|
||||
.SetMethod("toPng", &NativeImage::ToPNG)
|
||||
.SetMethod("toJpeg", &NativeImage::ToJPEG)
|
||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||
.SetMethod("getSize", &NativeImage::GetSize)
|
||||
.Build());
|
||||
|
@ -47,6 +49,14 @@ v8::Handle<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) {
|
|||
png->size());
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
|
||||
std::vector<unsigned char> output;
|
||||
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
|
||||
return node::Buffer::New(isolate,
|
||||
reinterpret_cast<const char*>(&output.front()),
|
||||
output.size());
|
||||
}
|
||||
|
||||
bool NativeImage::IsEmpty() {
|
||||
return image_.IsEmpty();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ class NativeImage : public mate::Wrappable {
|
|||
|
||||
private:
|
||||
v8::Handle<v8::Value> ToPNG(v8::Isolate* isolate);
|
||||
v8::Handle<v8::Value> ToJPEG(v8::Isolate* isolate, int quality);
|
||||
bool IsEmpty();
|
||||
gfx::Size GetSize();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue