PC Review


Reply
Thread Tools Rate Thread

Bitmap from IntPtr (Twain)

 
 
=?iso-8859-1?Q?J=F8rn_Jensen?=
Guest
Posts: n/a
 
      13th Jan 2006
Hey!
I have an issue with creating bitmap from an IntPtr. The IntPtr is created from a Twain scanner, which seem to work perfectly in it's original state (the app is originally written by somebody else). It's when I add the [Image.FromHbitmap] I get an error.

Extracts of my code and the error statement from the Visual Studio Debug bellow:
Select Case cmd

Case TwainCommand.CloseRequest

EndingScan()

tw.CloseSrc()

Case TwainCommand.CloseOk

EndingScan()

tw.CloseSrc()

Case TwainCommand.DeviceEvent

Case TwainCommand.TransferReady

Dim pics As ArrayList = tw.TransferPictures()

EndingScan()

tw.CloseSrc()

picnumber += 1

Dim i As Integer

For i = 0 To pics.Count - 1 Step 1

Dim img As IntPtr = CType(pics(i), IntPtr)

'Dim newpic As PicForm = New PicForm(img)

'newpic.MdiParent = Me

Dim picnum As Integer = i + 1

Dim imgScan As Image

imgScan = Image.FromHbitmap(pics(0)) '!!! Here is where I get the error statement: A generic error occured in GDI+

imgScanPreview.Image = imgScan

'newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" + picnum.ToString()

'newpic.Show()

Next

End Select



Here is where the image(s) are put in the "pics" arraylist:

Public Function TransferPictures() As ArrayList

Dim pics As ArrayList = New ArrayList()

If Equals(srcds.Id, IntPtr.Zero) Then

Return pics

End If

Dim rc As TwRC

Dim hbitmap As IntPtr = IntPtr.Zero

Dim pxfr As TwPendingXfers = New TwPendingXfers()

Do

pxfr.Count = 0

hbitmap = IntPtr.Zero

Dim iinf As TwImageInfo = New TwImageInfo()

rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf)

If (rc <> TwRC.Success) Then

CloseSrc()

Return pics

End If

rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, hbitmap)

If (rc <> TwRC.XferDone) Then

CloseSrc()

Return pics

End If

rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr)

If (rc <> TwRC.Success) Then

CloseSrc()

Return pics

End If

pics.Add(hbitmap)

Loop While (pxfr.Count <> 0)

rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr)

Return pics

End Function

Here is the exception stacktrace:

System.Runtime.InteropServices.ExternalException was unhandled
ErrorCode=-2147467259
Message="A generic error occurred in GDI+."
Source="System.Drawing"
StackTrace:
at System.Drawing.Image.FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
at System.Drawing.Image.FromHbitmap(IntPtr hbitmap)
at PMSDAWOE.MainFrame.PreFilterMessage(Message& m) in C:\NRK\Utvikling\PMS DAW OE\PMSDAWOE\PMSDAWOE\MainFrame.vb:line 133
at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG& msg, Boolean& modified)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at PMSDAWOE.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Thanks for any help!

- Jørn Jensen

 
Reply With Quote
 
 
 
 
New Member
Join Date: Jan 2012
Posts: 1
 
      12th Jan 2012
Did you find the solution for this?
I am having the same problem
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a bitmap from an intptr to scanned data mickey Microsoft VB .NET 3 21st Dec 2009 01:54 AM
Bitmap(int, int, int, PixelFormat, IntPtr) equivalent on CF? Thorium Microsoft Dot NET Compact Framework 0 10th Aug 2007 08:52 AM
ExtractIconEx(iconFullPath, -1, IntPtr.Zero, IntPtr.Zero, 0) does what??? Frank Microsoft C# .NET 0 28th Jan 2007 03:45 PM
IntPtr to IntPtr Copy =?Utf-8?B?UWluZ2RvbmcgWi4=?= Microsoft C# .NET 1 17th Feb 2005 12:19 AM
Scanner problems- says twain error, failed to open twain driver Ziaul Choudhury Windows XP Hardware 0 10th Jul 2003 12:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:15 AM.