Adds option to get raw data from NativeImage
This commit is contained in:
		
					parent
					
						
							
								af80b9a7df
							
						
					
				
			
			
				commit
				
					
						21962be60e
					
				
			
		
					 2 changed files with 11 additions and 0 deletions
				
			
		|  | @ -25,6 +25,7 @@ | |||
| #include "ui/gfx/geometry/size.h" | ||||
| #include "ui/gfx/image/image_skia.h" | ||||
| #include "ui/gfx/image/image_util.h" | ||||
| #include "third_party/skia/include/core/SkPixelRef.h" | ||||
| 
 | ||||
| #if defined(OS_WIN) | ||||
| #include "atom/common/asar/archive.h" | ||||
|  | @ -219,6 +220,14 @@ v8::Local<v8::Value> NativeImage::ToPNG(v8::Isolate* isolate) { | |||
|                             static_cast<size_t>(png->size())).ToLocalChecked(); | ||||
| } | ||||
| 
 | ||||
| v8::Local<v8::Value> NativeImage::ToRawBuffer(v8::Isolate* isolate) { | ||||
|   const SkBitmap* bitmap = image_.ToSkBitmap(); | ||||
|   SkPixelRef* ref = bitmap->pixelRef(); | ||||
|   return node::Buffer::Copy(isolate, | ||||
|                             reinterpret_cast<const char*>(ref->pixels()), | ||||
|                             bitmap->getSafeSize()).ToLocalChecked(); | ||||
| } | ||||
| 
 | ||||
| v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) { | ||||
|   std::vector<unsigned char> output; | ||||
|   gfx::JPEG1xEncodedDataFromImage(image_, quality, &output); | ||||
|  | @ -350,6 +359,7 @@ void NativeImage::BuildPrototype( | |||
|   mate::ObjectTemplateBuilder(isolate, prototype) | ||||
|       .SetMethod("toPNG", &NativeImage::ToPNG) | ||||
|       .SetMethod("toJPEG", &NativeImage::ToJPEG) | ||||
|       .SetMethod("toBUFFER", &NativeImage::ToRawBuffer) | ||||
|       .SetMethod("getNativeHandle", &NativeImage::GetNativeHandle) | ||||
|       .SetMethod("toDataURL", &NativeImage::ToDataURL) | ||||
|       .SetMethod("isEmpty", &NativeImage::IsEmpty) | ||||
|  |  | |||
|  | @ -70,6 +70,7 @@ class NativeImage : public mate::Wrappable<NativeImage> { | |||
|  private: | ||||
|   v8::Local<v8::Value> ToPNG(v8::Isolate* isolate); | ||||
|   v8::Local<v8::Value> ToJPEG(v8::Isolate* isolate, int quality); | ||||
|   v8::Local<v8::Value> ToRawBuffer(v8::Isolate* isolate); | ||||
|   v8::Local<v8::Value> GetNativeHandle( | ||||
|     v8::Isolate* isolate, | ||||
|     mate::Arguments* args); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Heilig Benedek
				Heilig Benedek