Save test.png in Cairo
Code: Select all
' cairo_test.bas
' simply displays a rectangle and saves as .png
#include once "cairo/cairo.bi"
Const SCREEN_W = 300
Const SCREEN_H = 300
ScreenRes SCREEN_W, SCREEN_H, 32
' Create a cairo drawing context, using the FB screen as surface.
Dim As cairo_surface_t Ptr surface = cairo_image_surface_create_for_data(ScreenPtr(), _
CAIRO_FORMAT_ARGB32, SCREEN_W, SCREEN_H, SCREEN_W * 4 )
Dim As cairo_t Ptr cr = cairo_create(surface)
ScreenLock
' draw the entire context white
cairo_set_source_rgba(cr, 1, 1, 1, 1)
cairo_paint(cr)
' black
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)
' draw a rectangle
cairo_rectangle (cr,100,100,100,100)
cairo_stroke (cr)
' write output
cairo_surface_write_to_png (surface, "test.png")
ScreenUnlock
' clean up the cairo surface and context
cairo_surface_destroy (surface)
cairo_destroy(cr)
sleep
Code: Select all
' wx-c_test.bas
' simply loads and displays a .png
' 32 bit only!
#Include Once "wx-c/wx.bi"
Dim Shared As wxApp Ptr wx_app
Dim Shared As wxFrame Ptr wx_frame
Dim Shared As wxPanel Ptr wx_panel
Declare Function App_OnInit WXCALL() As wxBool
Declare Function App_OnExit WXCALL() As wxInt
Declare Sub menuhandler WXCALL (ByVal event As wxEvent Ptr, ByVal iListener As wxInt)
Function App_OnInit WXCALL() As wxBool
wx_frame = wxFrame_ctor()
wxImage_InitAllHandlers()
wxFrame_Create( wx_frame, WX_NULL, -1, wxString_ctorUTF8("Test") ,-1, -1, 1024, 768, _
wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER, WX_NULL)
wx_panel = wxPanel_ctor2(wx_frame,-1,-1,-1,-1,-1,0,WX_NULL)
' past after wx_panel = wxPanel_ctor2( wx_frame, ...), to avoid error message
' comctl32.dll missing (Windows only):
wxGauge_Create(wxGauge_ctor(),wx_panel,-1,0,0,0,0,0,0,0,0)
' test bitmap
Dim As wxBitmap Ptr picimage0
Dim As wxStaticBitmap Ptr image0
picimage0 = wxBitmap_ctor()
image0 = wxStaticBitmap_ctor()
wxBitmap_LoadFile(picimage0,wxString_ctorUTF8("test.png"),wxBITMAP_TYPE_PNG)
wxStaticBitmap_Create(image0, wx_panel, -1, picimage0, 100, 100, 400, 400, 0, 0)
' center and show main window
wxWindow_CenterOnScreen(wx_frame,wxBOTH)
wxWindow_Show(wx_frame,1)
wxApp_OnInit(wx_app)
Return 1
end function
Sub EventHandler WXCALL ( event As wxEvent Ptr, iListener As wxInt )
Select Case wxEvent_GetEventType(event)
Case wxEvent_EVT_PAINT ()
Case wxEvent_EVT_IDLE()
End Select
end Sub
Function App_OnExit WXCALL() As wxInt
Return wxApp_OnExit(wx_app)
End Function
' main
wx_app = wxApp_ctor()
wxApp_RegisterVirtual(wx_app,@App_OnInit,@App_OnExit)
wxApp_Run(0, 0)
Question would be how to create a Cairo context within Wx-c?