Mark Sibly преди 9 години
родител
ревизия
e610dc742e
променени са 1 файла, в които са добавени 36 реда и са изтрити 0 реда
  1. 36 0
      modules/std/graphics/pixmapsaver.monkey2

+ 36 - 0
modules/std/graphics/pixmapsaver.monkey2

@@ -0,0 +1,36 @@
+
+Namespace std.graphics
+
+Private
+
+Using stb.image
+Using std.stream
+Using std.filesystem
+
+Struct WriteContext
+	Field stream:Stream
+End
+
+Function WriteFunc( context:Void Ptr,data:Void Ptr,size:Int )
+	Local stream:=Cast<WriteContext Ptr>( context )->stream
+	stream.Write( data,size )
+End
+
+Public
+
+#rem monkeydoc @hidden
+#end
+Function SavePixmap:Bool( pixmap:Pixmap,path:String )
+
+	Local stream:=Stream.Open( path,"w" )
+	If Not stream Return False
+	
+	Local context:WriteContext
+	context.stream=stream
+	
+	Local result:=stbi_write_png_to_func( WriteFunc,Varptr context,pixmap.Width,pixmap.Height,pixmap.Depth,pixmap.Data,pixmap.Pitch )
+	
+	stream.Close()
+	
+	Return result
+End