473,548 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FromHbitm ap] I get an error.

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

Case TwainCommand.Cl oseRequest

EndingScan()

tw.CloseSrc()

Case TwainCommand.Cl oseOk

EndingScan()

tw.CloseSrc()

Case TwainCommand.De viceEvent

Case TwainCommand.Tr ansferReady

Dim pics As ArrayList = tw.TransferPict ures()

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.MdiPare nt = Me

Dim picnum As Integer = i + 1

Dim imgScan As Image

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

imgScanPreview. Image = imgScan

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

'newpic.Show()

Next

End Select

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

Public Function TransferPicture s() 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.ImageNati veXfer, TwMSG.Get, hbitmap)

If (rc <> TwRC.XferDone) Then

CloseSrc()

Return pics

End If

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

If (rc <> TwRC.Success) Then

CloseSrc()

Return pics

End If

pics.Add(hbitma p)

Loop While (pxfr.Count <> 0)

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

Return pics

End Function

Here is the exception stacktrace:

System.Runtime. InteropServices .ExternalExcept ion was unhandled
ErrorCode=-2147467259
Message="A generic error occurred in GDI+."
Source="System. Drawing"
StackTrace:
at System.Drawing. Image.FromHbitm ap(IntPtr hbitmap, IntPtr hpalette)
at System.Drawing. Image.FromHbitm ap(IntPtr hbitmap)
at PMSDAWOE.MainFr ame.PreFilterMe ssage(Message& m) in C:\NRK\Utviklin g\PMS DAW OE\PMSDAWOE\PMS DAWOE\MainFrame .vb:line 133
at System.Windows. Forms.Applicati on.ThreadContex t.ProcessFilter s(MSG& msg, Boolean& modified)
at System.Windows. Forms.Applicati on.ThreadContex t.PreTranslateM essage(MSG& msg)
at System.Windows. Forms.Applicati on.ThreadContex t.System.Window s.Forms.UnsafeN ativeMethods.IM soComponent.FPr eTranslateMessa ge(MSG& msg)
at System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32 reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[] commandLine)
at PMSDAWOE.My.MyA pplication.Main (String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Thanks for any help!

- Jørn Jensen

Jan 13 '06 #1
0 3932

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

Similar topics

7
2013
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 control graphics object in the paint event. Any help would be appreciated. Here is my code: public class as mycontrol Private Declare Auto...
1
5341
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 am getting the cam preview to work and it is calling the FrameCallbackTarget function just fine... I just need to make the stream frame a bitmap.
15
7172
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 DrawToBitmap would work, but it appears that the webbrowser doesn't implement it. So I looked around and found that this code: Dim g As Graphics...
0
1734
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 will output. -- Start DLL code snippet private static extern unsafe Int16 GetHash(IntPtr Bitmap1, Int16 FilterNum, void* ImageHash); ///...
15
1816
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
2596
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
3478
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 class OnPagePrint method which only provides me an e.Graphic (see code sample below). The FCL doesn't seem to natively support Graphic...
8
4296
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 FromImage call will fail for indexed bitmaps.
1
3134
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 form into a picture box. - To do this, I bitblt using the device contexts of the form and a bitmap object. - After blitting, the bitmap image is...
0
7512
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.