TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Image Properties

Forums › TWAIN Classic › Image Properties

  • This topic has 1 reply, 1 voice, and was last updated 7 years, 6 months ago by si_ben.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • July 18, 2013 at 8:06 pm #22867 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    I’m trying to obtain an Image with the following specifications with no success…

    .Tiff (FileType)
    300 DPI (X,Y)
    BitDepth (1)
    Compression : CCITT T.6 (Group4)
    W(InPixels) 2550
    H(InPixels) 3300 (Letter Size)

    My Device doesn’t ‘support’ Compression or it won’t let me set it for some other reason and I also cannot use the
    ICAP_ImageFileFormat.

    I set my DPI like so :



    case (short)TwCap.IYResolution:
    // (Capability, 300DPI)
    t_Cap = new TwCapability(TwCap.IYResolution, 300);

    rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, t_Cap);
    // Check Result
    if (rc != TwRC.Success)
    {
    Report_Status();
    }
    break;

    I get success code from the set. Okay when I get to



    // Declare new instance of Image Information
    TwImageInfo iinf = new TwImageInfo();

    // Get Current Image Info
    rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);
    if (rc != TwRC.Success)
    {
    CloseSrc();
    return pics;
    }

    // Set to Native Transfer
    rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
    if (rc != TwRC.XferDone)
    {
    CloseSrc();
    return pics;
    }

    my iinf DOES Reflect the capabilities I set (I also set like B&W and stuff). When my image is saved and I view the properties, the DPI is 96, BitDepth is 32 and its RGB.

    Other notes, I chose not to show the UserInterface. So it never pops up. Right before I start scanning all the settings are proper. Im using NativeImageXfr.

    The only thing that I can determine is that there is a function that runs :



    public Image ImageFromIntPtr(IntPtr imagePtr)
    {
    BITMAPINFOHEADER bmpInfoHeader = new BITMAPINFOHEADER();

    IntPtr bmpptr = GlobalLock(imagePtr);
    IntPtr pixptr = GetPixelInfo(bmpptr, bmpInfoHeader);

    Bitmap bitmap = new Bitmap(bmpInfoHeader.biWidth, bmpInfoHeader.biHeight);
    Graphics graphics = Graphics.FromImage(bitmap);

    IntPtr hdc = graphics.GetHdc();

    SetDIBitsToDevice(hdc, 0, 0, bmpInfoHeader.biWidth, bmpInfoHeader.biHeight,
    0, 0, 0, bmpInfoHeader.biHeight, pixptr, bmpptr, 0);

    graphics.ReleaseHdc(hdc);

    return (Image)bitmap;
    }

    Thing is I dont know how to manipulate the fields of BITMAPINFOHEADER(). Whats going on!! When I use Twirl and I set the same capabilities it comes out like it should with the 300 DPI. What am I doing that messes up this image??

    July 22, 2013 at 2:06 pm #25941 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    I found one way to apply the compression and the DPI that I needed. Seems like there is more than one way to do it, but it was in my .Save() method [OfType(Image)].. Originally I was saving it just as (FileLocation, Image Extension)

    Here is the following code that helped me obtain my result :



    ///
    /// Save Button
    ///

    ///
    ///
    private void button2_Click(object sender, EventArgs e)
    {
    List list = nessScanning1.ImagesList;
    int i = 1;
    foreach (Image img in list)
    {
    ImageCodecInfo myImageCodecInfo;
    System.Drawing.Imaging.Encoder myEncoder;
    EncoderParameter myEncoderParameter;
    EncoderParameters myEncoderParameters;

    myImageCodecInfo = GetEncoderInfo("image/tiff");

    myEncoder = System.Drawing.Imaging.Encoder.Compression;

    myEncoderParameters = new EncoderParameters(1);

    myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
    myEncoderParameters.Param[0] = myEncoderParameter;
    Bitmap image;
    image = new Bitmap(img);
    image.SetResolution(300,300);
    image.Save(string.Format("C:\Temp\Pic_{0}.tiff", i++), myImageCodecInfo, myEncoderParameters);
    }
    }

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
    int j;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (j = 0; j < encoders.Length; ++j)
    {
    if (encoders[j].MimeType == mimeType)
    return encoders[j];
    }
    return null;
    }

    So if your scanner cannot support (CompressionFileType) there is still a way to obtain the result…

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Image Properties
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • To get the list of scanners from javascript client side (browser)
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.