谁能告诉我一个把*.raw格式的图象的文件转化成jpg或bmp格式的图象文件的程序(100分)

  • 主题发起人 straydog
  • 开始时间
S

straydog

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能告诉我一个把*.raw格式的图象的文件转化成jpg或bmp格式的图象文件的程序
 
准确来说,raw文件实际上是一个没有了文件头的bmp文件(只含象素信息),
只要知道了这幅图的宽、高和颜色深度,就可以轻松把它变成bmp图,
要变成jpg图你自己也会做了吧。
 
是用二进制编辑器做吗,我目前没有啊,你可以说清楚一点吗,有没有相关文章
 
关键是估计Width, Height和ColorDepth.
例如有一个raw文件,其大小为614400,则可以估计它为640x480x16bit的图像.
然后调用RawToBitmap(Stream, 640, 480, 16, Bmp);
注意:Stream为任意形式的流,Bmp为有效实例.
至于参数的估计只能靠人手估计了.

procedure RawToBitmap(Stream: TStream;
const Width, Height, ColorDepth: Integer; Bmp: TBitmap);
var
RemLen, DataLen, i: Integer;
begin
case ColorDepth of
1:
begin
Bmp.PixelFormat := pf1Bit;
DataLen := (Width + 7) shr 3;
end;
4:
begin
Bmp.PixelFormat := pf4Bit;
DataLen := (Width + 1) shr 1;
end;
8:
begin
Bmp.PixelFormat := pf8Bit;
DataLen := Width;
end;
15:
begin
Bmp.PixelFormat := pf15Bit;
DataLen := Width shl 1;
end;
16:
begin
Bmp.PixelFormat := pf16Bit;
DataLen := Width shl 1;
end;
24:
begin
Bmp.PixelFormat := pf24Bit;
DataLen := Width shl 1 + Width;
end;
32:
begin
Bmp.PixelFormat := pf32Bit;
DataLen := Width shl 2;
end;
end;
Bmp.Width := Width;
Bmp.Height := Height;
RemLen := (DataLen + 3) shr 2 shl 2 - DataLen;

Stream.Position := 0;
for i := 0 to Height - 1 do begin
Stream.Read(Bmp.ScanLine[Height - 1 - i]^, DataLen);
if RemLen <> 0 then
Stream.Seek(RemLen, soFromCurrent);
end;
end;
 
顶部