Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have used the following scheme to convert in-memory images to TBitmap:</p> <p>1) Fill TBMPHeader structure</p> <pre><code> TBMPHeader = packed record bmfHeader: TBitmapFileHeader; bmiHeader: TBitmapInfoHeader; bmiColors: {depends on image format, may be absent}; end; </code></pre> <p>2) Write BMPHeader + Image Data to MemoryStream</p> <p>3) Load TBitmap from MemoryStream using TBitmap.LoadFromStream</p> <p>You seems to have bmiHeader structure filled already. Add bmfHeader and (maybe) bmiColors.</p> <p>Here is the code I used to convert 256-color grayscale in-memory images to TBitmap (many years ago, sorry, so no details):</p> <pre><code>procedure TksImage.CopyToBitmap(Bitmap: TBitmap); var Stream: TStream; begin Stream:= TMemoryStream.Create; try SaveToStream(Stream); Stream.Position:= 0; Bitmap.LoadFromStream(Stream); finally Stream.Free; end; end; procedure TksImage.SaveToStream(Stream: TStream); type TBMPHeader = packed record bmfHeader: TBitmapFileHeader; bmiHeader: TBitmapInfoHeader; bmiColors: array[0..255] of TRGBQuad; end; var BMPHeader: TBMPHeader; N: LongWord; I: Integer; begin FillChar(BMPHeader, SizeOf(BMPHeader), 0); with BMPHeader.bmfHeader do begin bfType:= $4D42; {'BM'} bfOffBits:= SizeOf(BMPHeader); if FChannels = 4 then Dec(bfOffBits, SizeOf(BMPHeader.bmiColors)); bfSize:= bfOffBits + LongWord(FImageSize); end; with BMPHeader.bmiHeader do begin biSize:= SizeOf(BMPHeader.bmiHeader); biWidth:= FWidth; biHeight:= FHeight; biPlanes:= 1; biBitCount:= 8 * FChannels; biCompression:= BI_RGB; biSizeImage:= FImageSize; {((((biWidth * biBitCount) + 31) and not 31) shr 3) * biHeight;} end; N:= 0; for I:= 0 to 255 do begin LongWord(bmpHeader.bmiColors[I]):= N; Inc(N, $010101); end; Stream.Write(BMPHeader, BMPHeader.bmfHeader.bfOffBits); Stream.Write(FImageData^, FImageSize); end; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload