如何将BMP格式图像转成PCX格式!

54783szg 2003-09-24 11:46:26
我知道BMP和PCX头格式,现在问题是我如何将BMP格式通过读取->写入的方式变成PCX格式图像?
...全文
248 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ehom 2003-10-22
  • 打赏
  • 举报
回复
漏了

initialization
TPicture.RegisterFileFormat('PCX', 'Paintbrush images', TPCXGraphic);
finalization
TPicture.UnregisterGraphicClass(TRASGraphic);

注册一下就能用了

详细解释看
http://www.csdn.net/develop/Article/18/18699.shtm
ehom 2003-10-22
  • 打赏
  • 举报
回复
给段简单的代码,不支持RLE压缩,只能用8、24位两种色深写入

type
TPCXHeader = record
FileID: Byte;
Version: Byte;
Encoding: Byte;
BitsPerPixel: Byte;
XMin,
YMin,
XMax,
YMax,
HRes,
VRes: Word;
ColorMap: array[0..15] of TRGB;
Reserved,
ColorPlanes: Byte;
BytesPerLine,
PaletteType: Word;
Fill: array[0..57] of Byte;
end;

TPCXGraphic = class(TBitmap)
public
procedure SaveToStream(Stream: TStream); override;
end;

procedure TPCXGraphic.SaveToStream(Stream: TStream);
var
Header: TPCXHeader;
Run: Pointer;
Line, EncodeBuffer: PByte;
RLine, Gline, BLine: PByte;
X, Y, I: Integer;
Encoder: TPCXRLEDecoder;
BytesStored: Cardinal;
Filled: Boolean;
Pal: TMaxLogPalette;
Palarray:array[0..767] of Byte;
begin
Header.FileID := $0A;
Header.Version := 5;
Header.Encoding := 1;
Header.XMin := 0;
Header.YMin := 0;
Header.XMax := Width - 1;
Header.YMax := Height - 1;
Header.HRes := 72;
Header.VRes := 72;
FillChar(Header.ColorMap, 48, 0);
Header.Reserved := 1;
FillChar(Header.Fill,58,0);
case PixelFormat of
pf1bit,
pf4bit:
begin
PixelFormat := pf8bit;
Header.BitsPerPixel := 8;
Header.ColorPlanes := 1;
Header.BytesPerLine := (Width + 1) div 2 * 2;
Header.PaletteType := 0;
end;
pf8bit:
begin
Header.BitsPerPixel := 8;
Header.ColorPlanes := 1;
Header.BytesPerLine := (Width + 1) div 2 * 2;
Header.PaletteType := 0;
end;
pf24bit:
begin
Header.BitsPerPixel := 8;
Header.ColorPlanes := 3;
Header.BytesPerLine := (Width + 1) div 2 * 2;
Header.PaletteType := 0;
end;
else
begin
PixelFormat := pf24bit;
Header.BitsPerPixel := 8;
Header.ColorPlanes := 3;
Header.BytesPerLine := (Width + 1) div 2 * 2;
Header.PaletteType := 0;
end;
end;

Stream.Write(Header, SizeOf(Header));
Filled := Boolean(Width mod 2);

if PixelFormat = pf8bit then
begin
try
for Y := 0 to Height - 1 do
begin
Line := ScanLine[Y];
Stream.WriteBuffer(Line^, Width);
if Filled then
begin
I := 0;
Stream.WriteBuffer(I, 1);
end;
end;
GetPaletteEntries(Palette, 0, 256, Pal.palPalEntry);
for I := 0 to 255 do
begin
Palarray[3*I] := Pal.palPalEntry[I].peRed;
Palarray[3*I+1] := Pal.palPalEntry[I].peGreen;
Palarray[3*I+2] := Pal.palPalEntry[I].peBlue;
end;
I := $C;
Stream.WriteBuffer(I, 1);
Stream.WriteBuffer(Palarray, SizeOf(Palarray));
finally

end;
end
else
begin
try
GetMem(RLine, Width);
GetMem(GLine, Width);
GetMem(BLine, Width);
for Y := 0 to Height - 1 do
begin
Line := ScanLine[Y];
for X := 0 to Width - 1 do
begin
RLine^ := Line^;
Inc(RLine);
Inc(Line);
GLine^ := Line^;
Inc(GLine);
Inc(Line);
BLine^ := Line^;
Inc(BLine);
Inc(Line);
end;
Dec(BLine, Width);
Stream.WriteBuffer(BLine^, Width);
if Filled then
begin
I := 0;
Stream.WriteBuffer(I, 1);
end;
Dec(GLine, Width)
Stream.WriteBuffer(BLine^, Width);
if Filled then
begin
I := 0;
Stream.WriteBuffer(I, 1);
end;
Dec(RLine, Width);
Stream.WriteBuffer(BLine^, Width);
if Filled then
begin
I := 0;
Stream.WriteBuffer(I, 1);
end;
end;
finally
if Assigned(RLine) then FreeMem(RLine);
if Assigned(GLine) then FreeMem(GLine);
if Assigned(BLine) then FreeMem(BLine);
end;
end;
end;
klbt 2003-10-22
  • 打赏
  • 举报
回复
同意楼上。
GeoPhoenix 2003-09-25
  • 打赏
  • 举报
回复
采用二进制的方式打开,写一段转换代码就可以了

13,874

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧