Home › Forums › TWAIN Classic › Making a scanning preview › Reply To: Making a scanning preview
August 4, 2008 at 3:45 pm #24593
Can be this part of the problem maybe is not the triplet at all maybe it is the bmp watch this code:
function TTwainSource.PrepareMemXfer(var BitmapHandle: HBitmap; var PixelType: TW_INT16): TW_UINT16;
const
PixelColor: Array[TTwainPixelFlavor] of Array[0..1] of Byte =
((0, $FF), ($FF, 00), (0, $FF));
var
Handle: HGlobal;
Info: TW_IMAGEINFO;
Setup: TW_SETUPMEMXFER;
structsize, index, Size, Blocks: Integer;
XRes, YRes: Extended;
Pal : TW_PALETTE8;
vUnit : TTwainUnit;
vUnits: TTwainUnitSet;
Dib : pBitmapInfo;
PixelFlavor: TTwainPixelFlavor;
PixelFlavors: TTwainPixelFlavorSet;
DC: HDC;
Data : Pointer;
begin
{First of all, get information on the image being acquired}
Result := Owner.TwainProc(AppInfo, @Structure, DG_IMAGE, DAT_IMAGEINFO,MSG_GET, @Info);
if Result <> TWRC_SUCCESS then exit;
{Calculate image size}
with Info do
size := ((((ImageWidth * BitsPerPixel + 31) div 32)*4) * info.ImageLength);
{Obtain image buffer transference sizes}
Owner.TwainProc(AppInfo, @Structure, DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET, @Setup);
blocks := (size div Integer(setup.Preferred));
size := (blocks + 1) * Integer(setup.Preferred);
{Prepare new bitmap}
structsize := size + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
Handle := GlobalAlloc(GHND, StructSize);
Dib := GlobalLock(Handle);
Fillchar(Dib^, structsize, #0);
{Fill image information}
Dib^.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
Dib^.bmiHeader.biWidth := info.ImageWidth;
Dib^.bmiHeader.biHeight := info.ImageLength;
{Only 1 plane supported}
Dib^.bmiHeader.biPlanes := 1;
Dib^.bmiHeader.biBitCount := info.BitsPerPixel;
{No compression}
Dib^.bmiHeader.biCompression := BI_RGB;
Dib^.bmiHeader.biSizeImage := Size;
{Adjust units}
XRes := Fix32ToFloat(Info.XResolution);
YRes := Fix32ToFloat(Info.YResolution);
GetICapUnits(vUnit, vUnits);
case vUnit of
tuInches: begin
Dib^.bmiHeader.biXPelsPerMeter := Trunc((XRes*2.54)*100);
Dib^.bmiHeader.biYPelsPerMeter := Trunc((YRes*2.54)*100);
end;
tuCentimeters: begin
Dib^.bmiHeader.biXPelsPerMeter := Trunc(XRes*100);
Dib^.bmiHeader.biYPelsPerMeter := Trunc(YRes*100);
end
else begin
Dib^.bmiHeader.biXPelsPerMeter := 0;
Dib^.bmiHeader.biYPelsPerMeter := 0;
end
end {case vUnits of};
{Now it should setup the palette to be used by the image}
{by either building a definied palette or retrieving the}
{image's one}
Did u do something like this?