dynarithmic / twain_library

Dynarithmic TWAIN Library, Version 5.x
Apache License 2.0
60 stars 25 forks source link

Enumerating & get/set device capabilities and image transfer mechanism in Delphi #3

Closed chukkan closed 4 years ago

chukkan commented 4 years ago

Highly appreciated for a sample/demo in Delphi (Berlin or later) of enumerating the device capabilities (resolution, pixel-type, bit-depth, paper size etc.,), and get/set these capabilities, as well as a demo of different modes of image transfer mechanism.

dynarithmic commented 4 years ago

Hello,

Basically the way to set the pixel type in Delphi is the following:

var
   AllPixelTypes: DTWAIN_ARRAY;
   NumPixelTypes: LONG;
   PixelValue: LONG;
   i: LONG;
   Source: DTWAIN_SOURCE;
....
  { Assume that Source has been selected }
  DTWAIN_EnumPixelTypes(Source, @AllPixelTypes);
  NumPixelTypes := DTWAIN_ArrayGetCount(AllPixelTypes);
  for i  := 0 to NumPixelTypes - 1 do
  begin
     DTWAIN_ArrayGetAtLong(AllPixelTypes, i, @PixelValue);
     { The PixelValue is one of the supported pixel types for the Source }
  end
  { Clean up }
  DTWAIN_ArrayDestroy(AllPixelTypes);

So basically it is a matter of sending and processing a DTWAIN_ARRAY in Delphi for many, if not all of the functions with DTWAIN_ARRAY or LPDTWAIN_ARRAY arguments, So please extend this code to handle any function of DTWAIN that uses these argument types.

Note that for LPDTWAIN_ARRAY, we send the address of a DTWAIN_ARRAY and not the DTWAIN_ARRAY itself.

Also, I suggest you get the latest version of DTWAIN, or at least the latest version of the Delphi bindings, since they have been updated yesterday. The old versions had bugs (and honestly, only tested with very old versions of Delphi).

dynarithmic commented 4 years ago

Keeping this issue open, in case you have any further issues on using DTWAIN_ARRAY functions.

dynarithmic commented 4 years ago

Just to round this out, to get the device capabilities:

var
   AllCaps: DTWAIN_ARRAY;
   NumCaps: LONG;
   Cap: LONG;
   i: LONG;
   Source: DTWAIN_SOURCE;
....
  { Assume that Source has been selected }
  DTWAIN_EnumSupportedCaps(Source, @AllCaps);
  NumCaps := DTWAIN_ArrayGetCount(AllCaps);
  for i  := 0 to NumCaps - 1 do
  begin
     DTWAIN_ArrayGetAtLong(AllCaps, i, @Cap);
  end
  { Clean up }
  DTWAIN_ArrayDestroy(AllCaps);

Note the similarity to getting all the pixel types.

dynarithmic commented 4 years ago

To set the pixel value:

var
   AllPixelTypes: DTWAIN_ARRAY;
   NumPixelTypes: LONG;
   PixelValue: LONG;
   i: LONG;
   Source: DTWAIN_SOURCE;
   FirstPixelValue: LONG;
...
  { Assume that Source has been selected }
  DTWAIN_EnumPixelTypes(Source, @AllPixelTypes);
  NumPixelTypes := DTWAIN_ArrayGetCount(AllPixelTypes);
  for i  := 0 to NumPixelTypes - 1 do
  begin
     DTWAIN_ArrayGetAtLong(AllPixelTypes, i, @PixelValue);
     { The PixelValue is one of the supported pixel types for the Source }
  end

  { Let's set the first available pixel type we found in the array above }
  DTWAIN_ArrayGetAtLong(AllPixelTypes, 0, @FirstPixelValue);
  DTWAIN_SetPixelType(Source, FirstPixelValue, -1, 1);
  ...
  { Clean up }
  DTWAIN_ArrayDestroy(AllPixelTypes);