Home › Forums › TWAIN Classic › ImageLayout Problems… again…
- This topic has 3 replies, 1 voice, and was last updated 10 years, 9 months ago by si_ben.
- AuthorPosts
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?
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.
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
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…
- AuthorPosts