From d66dcb4fd7a429ba50ce5b3483f38df8b11718fc Mon Sep 17 00:00:00 2001 From: Nick's Hardware Youtube Channel <56885781+nickshardware@users.noreply.github.com> Date: Mon, 9 May 2022 19:11:15 -0400 Subject: [PATCH] transparent png --- rmabout.pas | 2 +- rwpng.pas | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/rmabout.pas b/rmabout.pas index 7fb172f..eb61f93 100644 --- a/rmabout.pas +++ b/rmabout.pas @@ -8,7 +8,7 @@ interface Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf; Const - ProgramName ='Raster Master v1.0 R44'; + ProgramName ='Raster Master v1.0 R45'; ProgramLicense = 'Released under MIT License'; type diff --git a/rwpng.pas b/rwpng.pas index 6172bd7..c932334 100644 --- a/rwpng.pas +++ b/rwpng.pas @@ -393,7 +393,7 @@ function ReadPNG(x,y,x2,y2 : integer;filename : string; LoadPalette : Boolean) : EasyPNG.Free; ReadPNG:=0; end; - +(* no transparent support procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer); var @@ -408,6 +408,7 @@ procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer); picture1.Bitmap.Width:=width; Picture1.Bitmap.height:=height; + picture1.Bitmap.PixelFormat:=pf32bit; for j:=0 to height-1 do begin for i:=0 to width-1 do @@ -419,6 +420,46 @@ procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer); end; end; end; + *) + +procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer); +var + width,height : integer; + i,j : integer; + ci : integer; + cr : TRMColorRec; + pixeldata : PByte; + pixelpos : longint; +begin + width:=x2-x+1; + height:=y2-y+1; + + picture1.Bitmap.Width:=width; + Picture1.Bitmap.height:=height; + picture1.Bitmap.PixelFormat:=pf32bit; //change format to 32 bit/RGBA + pixeldata:=picture1.Bitmap.RawImage.Data; + pixelpos:=0; + for j:=0 to height-1 do + begin + for i:=0 to width-1 do + begin + ci:=RMCoreBase.GetPixel(x+i,y+j); + RMCoreBase.Palette.GetColor(ci,cr); + pixeldata[pixelpos]:=cr.b; // Blue + pixeldata[pixelpos+1]:=cr.g; // Green + pixeldata[pixelpos+2]:=cr.r; // Red + if (cr.r = 255) and (cr.b=255) and (cr.g=0) then //if fuschia + begin + pixeldata[pixelpos+3]:=0; // Alpha 0 = transparent + end + else + begin + pixeldata[pixelpos+3]:=255; // Alpha 255 = solid + end; + inc(pixelpos,4); + end; + end; +end; Procedure TEasyPNG.SaveToFile(filename : string);