473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bitmap from IntPtr (Twain)

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.Pro cessFilters(MSG& msg, Boolean& modified)
at System.Windows.Forms.Application.ThreadContext.Pre TranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.Sys tem.Windows.Forms.UnsafeNativeMethods.IMsoComponen t.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.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.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Thanks for any help!

- Jørn Jensen

Jan 13 '06 #1
0 3911

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the...
1
by: Daniel Friend | last post by:
Hello, I have a question. I would like to know how I can convert the Video Header to a bitmap in VB .NET I searched everywhere and could not see how to do this. This is as far as I get. I...
15
by: dgk | last post by:
I'm trying to save the image of a webbrowser control. Not a particular image being shown on the page, but rather the visible display of the webbrowser. Using VS2005 I figured that maybe...
0
by: bcutting | last post by:
I have the following snippet of code which which makes a call into a dll to generate an array of bytes. Its arguments are a IntPtr to the bitmap, a number, and a reference to the array that it...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
0
by: news.microsoft.com | last post by:
Hi guys, This text looks long and complicate but it is not, and I really really need some help here. For the last 24hs I'm trying to resolve this issue (last night I dreamed
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.