RawLoad Example for Delphi
//This example loads RAW data into a LEAD control
//Raw data parameters are set in the LoadInfo event, which gets called
//when the file format is FILE_RAW, or any unrecognized file format
//The LoadInfo event obtains information through global variables
var
RasterIO: LEADRasterIO;
//Global variables used in the LoadInfo event
nWidth: Integer; //width of image
nHeight: Integer; //height of image
nBitsPerPixel: Integer; // bits per pixel of image--if palettized, a gray palette is generated
nViewPerspective: Integer; //view perspective of raw data (TOP_LEFT, BOTTOM_LEFT, etc)
bOrderBGR: boolean; //TRUE if order BGR, FALSE if order RGB
nOffset: Longint; //offset into file where raw data begins
bPadding: Boolean; //TRUE if each line of data is padded to four bytes
bReverseBits: Boolean; //TRUE if the bits of each byte are reversed
Procedure TForm1.LoadRawData(szFileName: String);
var
nRet: Integer;
begin
//Fill in the values of the global variables
//The global variables will get access in the LoadInfo event
nWidth:= 294;
nHeight:= 415;
nBitsPerPixel := 24;
nViewPerspective := BOTTOM_LEFT;
bOrderBGR := True;
nOffset := 100;
bPadding := True;
bReverseBits := True;
RasterIO := CreateComObject (CLASS_LEADRasterIO) as LEADRasterIO;
LEADEventSink1.Connect (RasterIO, _LEADRasterIOEvents);
nRet := RasterIO.Load (LEADRasterView1.Raster, szFileName, nBitsPerPixel, 0, 1);
if (nRet = 0) then
ShowMessage ('SUCCESS file load: ' + szFileName)
else
ShowMessage ('FAILED--file load: ' + szFileName);
end;
procedure TForm1. LEADEventSink1Invoke(Sender: TObject; DispID: Integer;
const IID: TGUID; LocaleID: Integer; Flags: Word; Params: tagDISPPARAMS;
varResult, ExcepInfo, ArgErr: Pointer);
var
nColors: Integer;
i: Longint;
nGray: Longint;
begin
case (DispID) of
LEADRASTERIOEVENTS_LOADINFO:
begin
RasterIO.LoadInfoFormat := FILE_RAW;
RasterIO.LoadInfoWidth := nWidth;
RasterIO.LoadInfoHeight := nHeight;
RasterIO.LoadInfoBits := nBitsPerPixel;
RasterIO.LoadInfoXRes := 150;
RasterIO.LoadInfoYRes := 150;
RasterIO.LoadInfoOffset := nOffset;
RasterIO.LoadInfoFlags := 0;
if (bPadding) then
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_PAD4;
if (bOrderBGR = False) then
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_ORDERRGB;
if (bReverseBits) then
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_LSB;
Case (nViewPerspective) of
TOP_LEFT:
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT;
BOTTOM_LEFT:
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_REVERSE;
TOP_RIGHT: //BOTTOM_LEFT180
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT180;
BOTTOM_RIGHT: //TOP_LEFT180
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT180;
RIGHT_TOP: //TOP_LEFT90
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT90;
LEFT_BOTTOM: //TOP_LEFT270
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_TOPLEFT270;
LEFT_TOP: //BOTTOM_LEFT90
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT90;
RIGHT_BOTTOM: //BOTTOM_LEFT270
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_BOTTOMLEFT270;
end;
//if image is palettized create a grayscale palette
if (nBitsPerPixel <= 8) then
begin
nColors := Trunc(Power(2, nBitsPerPixel));
RasterIO.LoadInfoFlags := RasterIO.LoadInfoFlags Or LOADINFO_PALETTE;
for i := 0 To nColors - 1 do
begin
nGray := Trunc((i * 256) / nColors);
RasterIO.IOPalette [i] := RGB(nGray, nGray, nGray)
end;
end;
end;
end;
end;