Delphi把一张PNG横向分割成N张透明通道的图片

Delphi新版本虽然集成了PngImage但是分割复制什么的却非常难用.稍微封装了一下.可以把一张PNG
横向分割成N张.透明通道什么的都可以保持不变.
type
TPngArray = array of TPngImage;
procedure CopyPng(const Src: TPngImage; dest: TPngImage;
const sOffset: Integer);
var
i, j, s: Integer;
p1, p2: PByteArray;
pa1, pa2: PByteArray;
begin
for i := 0 to Src.Height - 1 do
begin
p1 := Src.Scanline[i];
p2 := dest.Scanline[i];
pa1 := Src.AlphaScanline[i];
pa2 := dest.AlphaScanline[i];
for j := 0 to dest.Width - 1 do
begin
s := j + sOffset;
p2[3 * j] := p1[3 * s];
p2[3 * j + 1] := p1[3 * s + 1];
p2[3 * j + 2] := p1[3 * s + 2];
pa2[j] := pa1[s];
end;
end;
end;
function SplitePng(const Src: TPngImage; Count : Integer) : TPngArray;
var
I, lwidth,loffset : Integer;
begin
SetLength(Result, Count);
lwidth := Src.Width div Count;
loffset := 0;
for i := 0 to Count -1 do

begin
Result[i] := TPngImage.CreateBlank(COLOR_RGBALPHA, 8, lwidth, Src.Height);
CopyPng(Src, Result[i], lOffset);
Inc(loffset, lwidth);
end;
end;

posted @ 2013-09-02 09:45  Max Woods  阅读(839)  评论(0编辑  收藏  举报