pixmapsaver.monkey2 669 B

123456789101112131415161718192021222324252627282930313233343536
  1. Namespace std.graphics
  2. Private
  3. Using stb.image
  4. Using std.stream
  5. Using std.filesystem
  6. Struct WriteContext
  7. Field stream:Stream
  8. End
  9. Function WriteFunc( context:Void Ptr,data:Void Ptr,size:Int )
  10. Local stream:=Cast<WriteContext Ptr>( context )->stream
  11. stream.Write( data,size )
  12. End
  13. Public
  14. #rem monkeydoc @hidden
  15. #end
  16. Function SavePixmap:Bool( pixmap:Pixmap,path:String )
  17. Local stream:=Stream.Open( path,"w" )
  18. If Not stream Return False
  19. Local context:WriteContext
  20. context.stream=stream
  21. Local result:=stbi_write_png_to_func( WriteFunc,Varptr context,pixmap.Width,pixmap.Height,pixmap.Depth,pixmap.Data,pixmap.Pitch )
  22. stream.Close()
  23. Return result
  24. End