Skip to content

function cvImage2Bitmap() didn't work, i wrote a new one #134

Open
@OllinuxD

Description

@OllinuxD

function cvImage2Bitmap didn't work for me, it produced an exception.

this code instead works:

function cvImage2Bitmap(img: PIplImage): {$IFDEF DELPHIXE2_UP}Vcl.Graphics.TBitmap{$ELSE}Graphics.TBitmap{$ENDIF}; var bmp: {$IFDEF DELPHIXE2_UP}Vcl.Graphics.TBitmap{$ELSE}Graphics.TBitmap{$ENDIF}; deep: Integer; y, x, c, wStep, Channels: Integer; srcPtr: PByte; destPtr: PByte; wAdd: Integer; begin Result := nil; if (img <> nil) then begin bmp := {$IFDEF DELPHIXE2_UP}Vcl.Graphics.TBitmap.Create{$ELSE}Graphics.TBitmap.Create{$ENDIF}; bmp.SetSize(img^.Width, img^.Height); deep := img^.nChannels * img^.depth; case deep of 8: bmp.PixelFormat := pf8bit; 16: bmp.PixelFormat := pf16bit; 24: bmp.PixelFormat := pf24bit; 32: bmp.PixelFormat := pf32bit; end; wStep := img^.WidthStep; Channels := img^.nChannels; srcPtr := Pointer(img^.ImageData); wAdd := wStep - (img^.width * Channels); for y := 0 to img^.Height - 1 do begin destPtr := bmp.Scanline[y]; for x := 0 to img^.Width - 1 do begin for c := 0 to Channels - 1 do begin destPtr^ := srcPtr^; Inc(destPtr); Inc(srcPtr); end; end; srcPtr := Pointer(NativeUint(srcPtr) + NativeUInt(wAdd)); end; Result := bmp; end; end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions