Home > Archive > Visual Basic Syntax > January 2006 > Bitmap from Intptr (Twain)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Bitmap from Intptr (Twain)
|
|
| Jørn Jensen 2006-01-13, 7:58 am |
| 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()
| |
| Jeff Johnson [MVP: VB] 2006-01-13, 7:04 pm |
|
"Jørn Jensen" <jorn.jensen@mp3pro.no> wrote in message
news:u4Q5UWEGGHA.3936@TK2MSFTNGP12.phx.gbl...
> I have an issue with creating bitmap from an IntPtr.
This is a VB "classic" newsgroup. Questions about VB.NET (including VB 2005,
which has dropped .NET from its name) are off-topic here.
Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.
|
|
|
|
|