Z
zljzyj
Unregistered / Unconfirmed
GUEST, unregistred user!
我把一个BMP图像压缩,
但是当
BmpStream.ReadBuffer(Buf,SendSize);
时,出错,提示为Stream read error 其中SendSize为2048
对压缩以后的流文件也没有问题,因为我把它在写内buffer之前存入了一个临时文件,对此完全可以恢复,但不知为何写入BUffer却出错了。
对图像的压缩代码为
procedure Tform1.CompressBitmap(var CompressedStream: TMemoryStream;const CompressionLevel: TCompressionLevel);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
//获得图像流的原始尺寸
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(CompressionLevel, DestStream);
Try
//SourceStream中保存着原始的图像流
CompressedStream.SaveToStream(SourceStream);
//将原始图像流进行压缩, DestStream中保存着压缩后的图像流
SourceStream.Free;
compressedStream.Clear;
//写入原始图像的尺寸
CompressedStream.WriteBuffer(Count, SizeOf(Count));
//写入经过压缩的图像流
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;
但是当
BmpStream.ReadBuffer(Buf,SendSize);
时,出错,提示为Stream read error 其中SendSize为2048
对压缩以后的流文件也没有问题,因为我把它在写内buffer之前存入了一个临时文件,对此完全可以恢复,但不知为何写入BUffer却出错了。
对图像的压缩代码为
procedure Tform1.CompressBitmap(var CompressedStream: TMemoryStream;const CompressionLevel: TCompressionLevel);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
//获得图像流的原始尺寸
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(CompressionLevel, DestStream);
Try
//SourceStream中保存着原始的图像流
CompressedStream.SaveToStream(SourceStream);
//将原始图像流进行压缩, DestStream中保存着压缩后的图像流
SourceStream.Free;
compressedStream.Clear;
//写入原始图像的尺寸
CompressedStream.WriteBuffer(Count, SizeOf(Count));
//写入经过压缩的图像流
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;