Thread WxPerl: Pixel färben schnell gemacht (29 answers)
Opened by Mampfgnom at 2010-11-16 11:40

topeg
 2010-11-16 18:26
#142791 #142791
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
habe kurz herum experimentiert:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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);
}

View full thread WxPerl: Pixel färben schnell gemacht