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

ImageLayout Problems… again…

Forums › TWAIN Classic › ImageLayout Problems… again…

  • This topic has 3 replies, 1 voice, and was last updated 7 years, 5 months ago by si_ben.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • July 22, 2013 at 6:55 pm #22868 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    Okay so while in State 4 :

    I negotiate ICap_Units successfully to Inches.

    After that I call this



    // Attempt to Manually Set Image Size if TW_SS Unsupported
    switch (m_ImageLayout)
    {
    case "LET":
    // In Pixels (2550, 3300)
    TwImageLayout iil = new TwImageLayout();
    iil.Frame = new TwFrame();
    iil.FrameNumber = 1;
    iil.PageNumber = 1;
    iil.DocumentNumber = 1;

    // Get Current Image Info
    rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, iil);
    if (rc != TwRC.Success)
    {
    CloseSrc();
    }
    break;
    case "LEG":
    // In Pixels (2550, 4200)
    break;
    case "LED":
    break;
    }

    AccessViolationException Unhandled:
    I get an ‘Attempted to read or write protected memory. This is often an indication that other memory is corrupt.’

    Here are my Definitions :



    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal struct TwImageLayout
    {
    public TwFrame Frame;
    public Int32 DocumentNumber;
    public Int32 PageNumber;
    public Int32 FrameNumber;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal struct TwFrame
    {
    public Int32 Left; // TW_FRAME
    public Int32 Top;
    public Int32 Right;
    public Int32 Bottom;
    }

    [DllImport("twain_32.dll", EntryPoint = "#1")]
    private static extern TwRC DSilayout([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwImageLayout layout);

    Does anybody know what I’m doing wrong?

    July 23, 2013 at 3:20 pm #25942 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    Still haven’t figured it out.

    I use both (Twacker, Twirl) to debug my settings. And I’m in State(4) when I do the request operation. I kind of have a feeling it might have something to do with Allocating Memory space for the structure, but I don’t have to do that for the ImageInfo structure.

    Have I declared my Structures improperly?

    I think it’s probably more in the DSilayout declaration but I cannot find an example of how to declare the entry point.

    July 23, 2013 at 4:20 pm #25943 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    OOOOOOOOOOKAY…. Finally…

    Here is the code….

    Had :



    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal struct TwImageLayout
    {
    public TwFrame Frame;
    public Int32 DocumentNumber;
    public Int32 PageNumber;
    public Int32 FrameNumber;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal struct TwFrame
    {
    public Int32 Left; // TW_FRAME
    public Int32 Top;
    public Int32 Right;
    public Int32 Bottom;
    }

    Needed :



    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal class TwImageLayout
    {
    public TwFrame Frame;
    public ulong DocumentNumber;
    public ulong PageNumber;
    public ulong FrameNumber;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal class TwFrame
    {
    public TwFix32 Left; // TW_FRAME
    public TwFix32 Top;
    public TwFix32 Right;
    public TwFix32 Bottom;
    }

    Now I need to try and figure out this (Frac) and (Whole) stuff

    July 23, 2013 at 4:42 pm #25944 Reply
    si_ben
    Participant
    • Topics - 7
    • Replies - 22
    • Total Posts - 29

    All you have to do is use the Method of the TwFix32 Class

    Def:



    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    internal class TwFix32
    { // TW_FIX32
    public short Whole;
    public ushort Frac;

    public float ToFloat()
    {
    return (float)Whole + ((float)Frac / 65536.0f);
    }
    public void FromFloat(float f)
    {
    int i = (int)((f * 65536.0f) + 0.5f);
    Whole = (short)(i >> 16);
    Frac = (ushort)(i & 0x0000ffff);
    }
    }

    Example:



    iil = new TwImageLayout();
    iil.Frame = new TwFrame();

    // Get Current Image Info
    rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, iil);
    if (rc != TwRC.Success)
    {
    //CloseSrc();
    }

    _right = iil.Frame.Right;
    _bottom = iil.Frame.Bottom;

    _right.FromFloat(8.5F);
    _bottom.Frac = 0;
    _bottom.Whole = 14;

    iil.Frame.Right = _right;
    iil.Frame.Bottom = _bottom;

    Thank you, Thank you… I know I know…

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: ImageLayout Problems… again…
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

  • Girls of Desire: All babes in one place, crazy, art
  • 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.
  • 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.