Autor Beitrag
Calyptus
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Di 14.12.04 23:19 
Ich kopiere per Scanline ein Bitmap aus einem Image auf ein Panel. Allerdings kommt das raus:

user defined image

Egal was für ein bild ich kopier, es kommt immer so was komisch rotes und verzogenes raus :shock:

Mein Code:

ausblenden Delphi-Quelltext
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:
procedure TForm1.Button1Click(Sender: TObject);
var
P : PByteArray;
a, b: Integer;
begin
 a := 0;
 b := 0;

 while a < Image1.Height - 1 do
  begin
   try
   P := Image1.Picture.Bitmap.ScanLine[a];
   except
   end;
   while b < Image1.Width - 1 do
    begin
     try
     Canvas.Pixels[b,a] := P[b];
     finally
     b := b + 1;
     end;
    end;
    a := a + 1;
    b := 0;
  end;
end;


Kann mir jmd sagen woran das liegt oder was ich falsch mache?

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 14.12.04 23:58 
Soweit ich das im Gedächtnis habe, arbeitet Scanline mit Pointern. Und ich sehe kein einziges ^ in deinem Quelltext :?

AXMD
Calyptus Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Mi 15.12.04 00:04 
d.h ... ???

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mi 15.12.04 00:07 
Das mit den Pointern stimmt schon so.. das Problem ist vermutlich eher, dass du mit 24bit-Bitmaps arbeitest und dort jeder Pixel 3 Bytes hat, du nimmst aber immer nur das erste Byte..

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Calyptus Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Mi 15.12.04 00:10 
ok.. und wie nehme ich alle 3?

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
Pr0g
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 220


D7 Pers
BeitragVerfasst: Mi 15.12.04 00:13 
Hallo,

wie kopierst du das Bitmap denn auf das Panel? Du nimmst doch das Canvas der Form, hier mal eine Verkürzung deines Codes:
ausblenden Delphi-Quelltext
1:
  BitBlt(Canvas.Handle, 0, 0, Image1.Width, Image1.Height, Image1.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);					


MfG Pr0g
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mi 15.12.04 00:37 
Die einfachere Methode ist natürlich per BitBlt o.ä.

Aber falls du es dennoch per ScanLine machen willst geht das zB so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Button1Click(Sender: TObject);
type
  PRGB = ^TRGB;
  TRGB = packed record
    B, G, R: Byte;
  end;

var
  p : PRGB;
  i, j: Integer;
begin
  for i := 0 to Image1.Picture.Bitmap.Height - 1 do
  begin
    p := Image1.Picture.Bitmap.ScanLine[i];
    for j := 0 to Image1.Picture.Bitmap.Width - 1 do
    begin
      Paintbox1.Canvas.Pixels[j, i] := RGB(p.R, p.G, p.B);
      Inc(p);
    end;
  end;
end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!