Autor Beitrag
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 16.02.03 13:09 
Ich war mir nicht sicher, ob das zu Grafik oder API gehört, aber vermutlich eher zu API...

Wie kann ich aus einem Bitmap eine Windows-Region erzeugen, und zwar so, daß eine Farbe übergeben wird, und alles, was nicht diese Farbe ist, gehört zur Region.

Beispiel: Ein Bild mit wirren Mustern. Der Hintergrund ist schwarz. Alles, was schwarz ist, soll transparent sein, also die wirren Muster sollen die Region sein.
Irgendwelche Vorschläge, wie ich sowas hinkriege?

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
mortus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mo 17.02.03 12:12 
ausblenden volle Höhe 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:
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:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
unit Unit1; 

interface 

uses 
  Windows, Classes, SysUtils, Graphics, Forms; 

type 
  TRGBArray = array[0..32767] of TRGBTriple; 
  PRGBArray = ^TRGBArray; 

type 
  TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
    procedure FormDestroy(Sender: TObject); 
  private 
    { Private declarations } 
    FRegion: THandle; 
    function CreateRegion(Bmp: TBitmap): THandle; 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.dfm} 

function TForm1.CreateRegion(Bmp: TBitmap): THandle; 
var 
  X, Y, StartX: Integer; 
  Excl: THandle; 
  Row: PRGBArray; 
  TransparentColor: TRGBTriple; 
begin 
  Bmp.PixelFormat := pf24Bit; 
  Result := CreateRectRGN(0, 0, Bmp.Width, Bmp.Height); 

  for Y := 0 to Bmp.Height - 1 do 
  begin 
    Row := Bmp.Scanline[Y]; 
    StartX := -1
    if Y = 0 then 
      TransparentColor := Row[0]; 
    for X := 0 to Bmp.Width - 1 do 
    begin 
      if (Row[X].rgbtRed = TransparentColor.rgbtRed) and 
        (Row[X].rgbtGreen = TransparentColor.rgbtGreen) and 
        (Row[X].rgbtBlue = TransparentColor.rgbtBlue) then 
      begin 
        if StartX = -1 then StartX := X; 
      end 
      else 
      begin 
        if StartX > -1 then 
        begin 
          Excl := CreateRectRGN(StartX, Y, X + 1, Y + 1); 
          try 
            CombineRGN(Result, Result, Excl, RGN_DIFF); 
            StartX := -1
          finally 
            DeleteObject(Excl); 
          end; 
        end; 
      end; 
    end; 
    if StartX > -1 then 
    begin 
      Excl := CreateRectRGN(StartX, Y, Bmp.Width, Y + 1); 
      try 
        CombineRGN(Result, Result, Excl, RGN_DIFF); 
      finally 
        DeleteObject(Excl); 
      end; 
    end; 
  end; 
end

procedure TForm1.FormCreate(Sender: TObject); 
var 
  Bmp: TBitmap; 
begin 
  Bmp := TBitmap.Create; 
  try 
    Bmp.LoadFromFile('C:\YourBitmap.bmp'); 
    FRegion := CreateRegion(Bmp); 
    SetWindowRGN(Handle, FRegion, True); 
  finally 
    Bmp.Free; 
  end; 
end

procedure TForm1.FormDestroy(Sender: TObject); 
begin 
  DeleteObject(FRegion); 
end;
 
end.
tommie-lie Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mo 17.02.03 19:39 
danke!
Genau das, was ich brauche!

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mi 13.08.03 05:38 
Den Code brauchte ich auch gerade, ich fand im Forum das:
www.delphi-forum.de/...windowrgn+combinergn

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.