Add initial crop method

This commit is contained in:
Kevin Sawicki 2016-10-04 11:23:18 -07:00
parent a80f4c1605
commit 2b4fff70d5
2 changed files with 13 additions and 0 deletions

View file

@ -309,6 +309,15 @@ mate::Handle<NativeImage> NativeImage::Resize(
new NativeImage(isolate, gfx::Image(resized)));
}
mate::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& bounds) {
gfx::ImageSkia cropped = gfx::ImageSkiaOperations::ExtractSubset(
image_.AsImageSkia(), bounds);
return mate::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(cropped)));
}
#if !defined(OS_MACOSX)
void NativeImage::SetTemplateImage(bool setAsTemplate) {
}
@ -410,6 +419,7 @@ void NativeImage::BuildPrototype(
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
.SetMethod("isTemplateImage", &NativeImage::IsTemplateImage)
.SetMethod("resize", &NativeImage::Resize)
.SetMethod("crop", &NativeImage::Crop)
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
.SetMethod("toPng", &NativeImage::ToPNG)
.SetMethod("toJpeg", &NativeImage::ToJPEG);

View file

@ -11,6 +11,7 @@
#include "base/values.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h"
#if defined(OS_WIN)
@ -78,6 +79,8 @@ class NativeImage : public mate::Wrappable<NativeImage> {
mate::Arguments* args);
mate::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
mate::Handle<NativeImage> Crop(v8::Isolate* isolate,
const gfx::Rect& bounds);
std::string ToDataURL();
bool IsEmpty();
gfx::Size GetSize();