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
| FUNCTION RGBtoRGBTriple(CONST red, green, blue: BYTE): TRGBTriple;
BEGIN
WITH RESULT DO
BEGIN
rgbtRed := red;
rgbtGreen := green;
rgbtBlue := blue
END
END {RGBTriple};
FUNCTION RGBAtoQuadBGRA(CONST red, green, blue, reserved: BYTE): TRGBQuad;
BEGIN
WITH RESULT DO
BEGIN
rgbRed := red;
rgbGreen := green;
rgbBlue := blue;
rgbReserved := reserved;
END
END {RGBQuad};
function BytesPerPixel(APixelFormat: TPixelFormat): integer;
begin
Result := -1;
case APixelFormat of
pf8bit : result := 1;
pf16bit: result := 2;
pf24bit: result := 3;
pf32bit: result := 4;
end;
end;
procedure TForm1.btnRussagainClick(Sender: TObject);
const
WSIZE = 320; // largeur
HSIZE = 240; // hauteur
TYPE // http://freepascal.ru/forum/viewtopic.php?t=11041&p=95820
TArrayOfByte = array of TRGBQuad;
// TArrayOfByte = array of TRGBTriple; // raies verticales !?
VAR
bmp: TBitmap;
h, w: integer;
AoB: TArrayOfByte;
fs : TFileStream;
FileSize: Integer;
BPP: integer;
begin
bmp := TBitmap.Create;
TRY
with bmp do begin
PixelFormat := pf32bit; // ou pf24bit, pour passer du rouge au bleu
SetSize(WSIZE, HSIZE);
BPP := BytesPerPixel(PixelFormat);
FileSize := WSIZE * HSIZE * BPP;
SetLength(AoB, FileSize);
//Image4.Picture.Bitmap.PixelFormat:=PixelFormat; // mis pour voir si pf24/32 avait une influence, mais non
end;
//1-remplissage de l'array (ici demande = rouge transparent)
for h := 0 to HSIZE-1 do
for w := 0 to WSIZE-1 do
//AoB[(h*WSIZE)+w] := RGBtoRGBTriple(255, 0, 0); // raies verticales !?
AoB[(h*WSIZE)+w] := RGBAtoQuadBGRA(255, 0, 0, 127);
//attention à l'ordre (selon 24 ou 32) ! /!\ B G R A en mode 32 /!\ dans fic : 00 00 FF 7F
//fs := TFileStream.Create('test3005_32.bin', fmCreate);
//fs.WriteBuffer(pointer(AoB)^, FileSize);
//fs.Free;
//2-affichage (= génération du bmp)
bmp.BeginUpdate;
for h := 0 to HSIZE-1 do
//Move(AoB[h], bmp.ScanLine[h]^, WSIZE*BPP); // /!\ Ne pas utiliser BPP ! (sinon carré rouge et quart noir en mode pf24)
Move(AoB[h], bmp.ScanLine[h]^, WSIZE*4);
bmp.EndUpdate;
// bmp.SaveToFile('test3005_32_BGRA.bmp');
Image4.Picture.Graphic := bmp;
FINALLY
bmp.Free;
END
end; |
Partager