Recent

Author Topic: How to make a 32bits PNG image without transparency  (Read 3048 times)

phabyam

  • Newbie
  • Posts: 4
How to make a 32bits PNG image without transparency
« on: November 16, 2012, 06:43:39 am »
Hola amigos!

I need to generate a 32bits png image without transparent pixels, I'm doing this

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  Png : TPortableNetworkGraphic;
begin
  Png := TPortableNetworkGraphic.Create;

  Png.PixelFormat:=pf32bit;
  Png.Transparent:=False;
  //Png.TransparentColor:=clNone;
  Png.SetSize(256,256);

  Png.Canvas.Brush.Color:=clBlue;
  Png.Canvas.FillRect(0,0,256,256);

  Png.Canvas.Brush.Color:=clYellow;
  Png.Canvas.Ellipse(10,10,246,246);

  Png.SaveToFile('E:\Archivos\Escritorio\DrawTest.png');
  Png.Free;
end;   

but the saved image have transparent pixels, check this http://i.imgur.com/75MmE.png  %)

when I change   Png.PixelFormat:=pf32bit; to pf24bits the saved image is OK , check this http://i.imgur.com/hDqX8.png, but unfortunately I need the image in 32bits pixel format

Helpme guys,

sorry my poor english
« Last Edit: November 16, 2012, 06:51:21 am by phabyam »

Imants

  • Full Member
  • ***
  • Posts: 196
Re: How to make a 32bits PNG image without transparency
« Reply #1 on: November 16, 2012, 08:09:03 am »
try something like this

  lazimg := TLazIntfImage.Create(256, 256);
  drawer := TLazCanvas.create(lazimg);
  drawer.Rectangle(0, 0, 255, 255);
  FStream := TFileStream.Create('C:\test.png', fmOpenWrite);

  FWrite := TFPWriterPNG.create;
  FWrite.UseAlpha := False;
  FWrite.WordSized := False;
  lazimg.SaveToStream(FStream, FWrite); 

  drawer.Free;
  FStream .Free;
  FWrite.Free;
  lazimg.Free;


circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: How to make a 32bits PNG image without transparency
« Reply #2 on: November 16, 2012, 08:43:37 am »
What do you mean by 32 bits ? If it's RGB each 8 bits, then it means that there is an implicit alpha channel. So you need to fill it with zeroes for example with something like "for each pixel, get color, change alpha color to zero and set color"
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018