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;
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;