图片转内存流问题,请朋友帮忙。(200)

N

nanshan

Unregistered / Unconfirmed
GUEST, unregistred user!
内存流转图片是成功的,可是图片转内存流后不能成功,请朋友帮我看看是哪里错了。转图片代码function TCapture.CreateBitmap(Buffer: Pointer;
Size: Integer): TBitmap;var iByteCount: Integer;
SrcScanLine, DstScanLine: PByteArray;
SrcX, SrcY, DstY: Integer;
begin
Result := nil;
// oh no, go out if (Buffer = nil) or (Size <= 0) then
Exit;
// read the bytecount iByteCount := Size div (FVideoWidth * FVideoHeight);
// wrong frame size?? if not iByteCount in [1..4] then
Exit;
Result := TBitmap.Create;
// set bitmap dimensions Result.Width := FVideoWidth;
Result.Height := FVideoHeight;
// set right pixelformat case iByteCount of 1: Result.PixelFormat := pf8Bit;
2: Result.PixelFormat := pf16Bit;
3: Result.PixelFormat := pf24Bit;
4: Result.PixelFormat := pf32Bit;
end;

// copy the bytes SrcY := 0;
DstY := FVideoHeight - 1;
// flip destination vertical while SrcY < FVideoHeightdo
begin
DstScanLine := Result.ScanLine[DstY];
SrcScanLine := Pointer(Integer(Buffer) + (SrcY * FVideoWidth * iByteCount));
SrcX := 0;
while SrcX < FVideoWidth * iByteCountdo
begin
DstScanLine[SrcX] := SrcScanLine[SrcX];
Inc(SrcX);
end;

Inc(SrcY);
Dec(DstY);
end;

end;
转内存流代码procedure TCapture.CreateFrame(Bitmap: TBitmap;
var Buffer: Pointer;var Size: Integer);var SrcScanLine : PByteArray;
SrcX, SrcY: Integer;
Buf: array of Byte;
begin
Size:= Bitmap.Width * Bitmap.Height * 3;
SetLength(Buf, Size);
// copy the bytes SrcY := 0;
while SrcY < Bitmap.Heightdo
begin
SrcScanLine := Bitmap.ScanLine[SrcY];
SrcX := 0;
while SrcX < Bitmap.Width * 3do
begin
Buf[SrcY * Bitmap.Width * 3 + SrcX] := SrcScanLine[SrcX];
Inc(SrcX);
end;

Inc(SrcY);
end;

Buffer:= Pointer(Buf);
end;
 
1、Buf是局部变量2、转内存流时你只处理了24位的格式
 
那怎么处理能包含 32位呢,谢谢了
 
http://www.efg2.com/Lab/ImageProcessing/Scanline.htm
 
以前做过类似东西,时间长了就忘了,你可以在网上搜搜“开发Delphi对象式数据管理功能”,里面有对数据流(TStream及其子类)的介绍,可以对图片“文件”或图片“本身”放入数据流中或读出,我觉得用数据流会更方便,不知是不是你所需要的?
 
像素格式由 TBitmap.PixelFormat属性来读取。错误关键是,输出的只是像素矩阵,没有包含文件头和图像头所以不能直接作为像素文件来使用,而且格式不一定就是24位的。
 
问题已经解决了,但是新的问题出现了,先散分
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
595
import
I
I
回复
0
查看
609
import
I
I
回复
0
查看
688
import
I
顶部