#!/usr/bin/perl use strict; use warnings; use Wx qw[:allclasses]; test->new->MainLoop; package test; use base qw(Wx::App); use Wx::Event qw (EVT_BUTTON); sub OnInit { my $frame = Wx::Frame->new( undef, -1, "Apfelmaennchen", [-1,-1], [1000,1000]); my $button_render = Wx::Button->new($frame,-1,"Malen",[0,0],[1000,50]); my $panel = Wx::Panel->new($frame, -1, [0,55],[1000,800]); $frame->{tafel} = Wx::StaticBitmap->new( $panel, -1, Wx::Bitmap->new( 0, 0, -1), [100,1]); my $button_exit = Wx::Button->new($frame,-1,"EXIT",[0,950],[1000,50]); my $dc = $frame->{dc} = Wx::MemoryDC->new(); $dc->Clear(); EVT_BUTTON($frame,$button_render, sub{ malen($frame); }); EVT_BUTTON($frame,$button_exit, sub{ $frame->Close }); $frame->Show(1); } sub malen { my $frame=shift; my ($width,$height)=(800,800); my $data=''; for(1..$width) { for(1..$height) { $data.=pack('C3',255,0,0); } } my $bmp=data_to_pixmap($data,$width,$height); $frame->{tafel}->SetBitmap( $bmp ); $frame->{dc}->SelectObject( $bmp ); $frame->{tafel}->Refresh(); } sub data_to_pixmap { my ($data,$width,$height)=@_; my $wximg=Wx::Image->new( $width, $height, $data ); return Wx::Bitmap->new($wximg); }