procedure LoadBitmap32FromPNG(fname: string; bm32: TBitmap32);
var
png: TPngObject;
tc: TColor32;
x, y: Integer;
bm: TBitmap;
p: pngimage.PByteArray;
begin
bm := nil;
png := nil;
try
png := TPngObject.Create;
png.LoadFromFile(fname);
bm := TBitmap.Create;
bm.Assign(png);
bm32.Assign(bm);
bm32.ResetAlpha;
case png.TransparencyMode of
ptmBit: begin
tc := Color32(png.TransparentColor);
for y := 0 to bm32.Height - 1 do
for x := 0 to bm32.Width - 1 do
if bm32.Pixel[x, y] = tc then PRGBQuad(bm32.PixelPtr[x, y])^.rgbReserved := 0;
end;
ptmPartial: begin
if (png.Header.ColorType = COLOR_GRAYSCALEALPHA) or
(png.Header.ColorType = COLOR_RGBALPHA) then begin
for y := 0 to bm32.Height - 1 do begin
p := png.AlphaScanline[y];
for x := 0 to bm32.Width - 1 do
PRGBQuad(bm32.PixelPtr[x, y])^.rgbReserved := p[x];
end;
end;
end;
end;
finally
if Assigned(bm) then bm.Free;
if Assigned(png) then png.Free;
end
end;
var
png: TPngObject;
tc: TColor32;
x, y: Integer;
bm: TBitmap;
p: pngimage.PByteArray;
begin
bm := nil;
png := nil;
try
png := TPngObject.Create;
png.LoadFromFile(fname);
bm := TBitmap.Create;
bm.Assign(png);
bm32.Assign(bm);
bm32.ResetAlpha;
case png.TransparencyMode of
ptmBit: begin
tc := Color32(png.TransparentColor);
for y := 0 to bm32.Height - 1 do
for x := 0 to bm32.Width - 1 do
if bm32.Pixel[x, y] = tc then PRGBQuad(bm32.PixelPtr[x, y])^.rgbReserved := 0;
end;
ptmPartial: begin
if (png.Header.ColorType = COLOR_GRAYSCALEALPHA) or
(png.Header.ColorType = COLOR_RGBALPHA) then begin
for y := 0 to bm32.Height - 1 do begin
p := png.AlphaScanline[y];
for x := 0 to bm32.Width - 1 do
PRGBQuad(bm32.PixelPtr[x, y])^.rgbReserved := p[x];
end;
end;
end;
end;
finally
if Assigned(bm) then bm.Free;
if Assigned(png) then png.Free;
end
end;
'프로그래밍 > Delphi' 카테고리의 다른 글
StretchBitBlt를 이용한 이미지 확대 축소 (0) | 2009.11.06 |
---|---|
URLEncoding 함수 사용하기 (1) | 2009.11.04 |
TIdHTTP.Post로 질의 및 결과 받기 (0) | 2009.11.04 |
"coreide70.bpl" Access violation 오류 대처법 - 통합IDE 환경에서 디버깅 오류 (2) | 2009.10.06 |
[TIP] TWebBrowser 메모리 증가 방지 처리 (4) | 2009.05.12 |