473,584 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WIA.ImageFile to System.Drawing. Image

I am creating an imaging service using WIA (Windows Imaging
Acquisition).

The problem is that I cannot convert a WIA.ImageFile to a
System.Drawing. Image to put a timestamp on the image without first
saving the file using the wia.imagefile.s avefile then loading it again
using System.Drawing. Image.FromFile. This seems pretty ineffecient. I
have tried coverting it using ctype, but I get an invalid cast
exception. Is anyone aware of how to accomplish this without saving and
reloading the file? I appreciate your time...

Thanks,
Jeremy

Dim mydevice As WIA.Device
Dim manager As New WIA.DeviceManag erClass
Dim mydialog As New WIA.CommonDialo gClass
Dim strcmdTakePictu re As String =
WIA.CommandID.w iaCommandTakePi cture
Dim strImageformat As String = WIA.FormatID.wi aFormatJPEG
Dim myItem As WIA.Item
Dim myImage As WIA.ImageFile
Dim strFilePath As String = Application.Sta rtupPath &
"\Images\Dummy. jpg"

For Each info As WIA.DeviceInfo In manager.DeviceI nfos
'Connect w/o dialog
If info.DeviceID =
"{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0 000" Then
mydevice = info.Connect
End If
Next

If IsNothing(mydev ice) Then
mydevice =
mydialog.ShowSe lectDevice(WIA. WiaDeviceType.V ideoDeviceType, False,
True)
End If

myItem = mydevice.Execut eCommand(strcmd TakePicture)

myImage = CType(myItem.Tr ansfer(strImage format), WIA.ImageFile)

'Need to covert to image here instead of SaveFile
myImage.SaveFil e(strFilePath)

Jan 5 '06 #1
2 11176
Hi,

Maybe this will help

http://msdn.microsoft.com/coding4fun...e/default.aspx

Ken
--------------
"Jeremy" <sl********@hot mail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
I am creating an imaging service using WIA (Windows Imaging
Acquisition).

The problem is that I cannot convert a WIA.ImageFile to a
System.Drawing. Image to put a timestamp on the image without first
saving the file using the wia.imagefile.s avefile then loading it again
using System.Drawing. Image.FromFile. This seems pretty ineffecient. I
have tried coverting it using ctype, but I get an invalid cast
exception. Is anyone aware of how to accomplish this without saving and
reloading the file? I appreciate your time...

Thanks,
Jeremy

Dim mydevice As WIA.Device
Dim manager As New WIA.DeviceManag erClass
Dim mydialog As New WIA.CommonDialo gClass
Dim strcmdTakePictu re As String =
WIA.CommandID.w iaCommandTakePi cture
Dim strImageformat As String = WIA.FormatID.wi aFormatJPEG
Dim myItem As WIA.Item
Dim myImage As WIA.ImageFile
Dim strFilePath As String = Application.Sta rtupPath &
"\Images\Dummy. jpg"

For Each info As WIA.DeviceInfo In manager.DeviceI nfos
'Connect w/o dialog
If info.DeviceID =
"{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0 000" Then
mydevice = info.Connect
End If
Next

If IsNothing(mydev ice) Then
mydevice =
mydialog.ShowSe lectDevice(WIA. WiaDeviceType.V ideoDeviceType, False,
True)
End If

myItem = mydevice.Execut eCommand(strcmd TakePicture)

myImage = CType(myItem.Tr ansfer(strImage format), WIA.ImageFile)

'Need to covert to image here instead of SaveFile
myImage.SaveFil e(strFilePath)

Jan 5 '06 #2
Thanks for your reply Ken. Actually this is one resource I used to
learn WIA. In the example however, he simply saves the file. I want to
convert it to a System.Drawing. Image first so I can alter the image
(add a time stamp). You can not programatically alter a wia.imagefile.
I was hoping someone could assist me in coverting a wia.imagefile to a
drawing.image without saving and reloading the file. Dim bmap as Image
= ctype(MyWiaImag e,Image) causes an invalid cast exception.

Jan 5 '06 #3

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

Similar topics

7
14206
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method, then use the GetThumbnailImage method to create a second Image. This second one is the one I want to get a FileStream from, so that I can then use...
3
20039
by: anastasia | last post by:
I get an out of memory exception when attempting to excecute the following code: original = System.Drawing.Image.FromFile(file.FileName,true); I ONLY get this exception when the file is in the "My Documents" folder or subfolders. If the file lives anywhere else on the hard drive, I have no problems. What could be going on here?
1
8132
by: Mchuck | last post by:
I've seen several newsgroup topics everywhere concerning this, as well as a couple of articles from the MSDN website, but this error still baffles me. It has to do with using the Image.FromStream(...) function to load an image into a PictureBox control from a byte array received from an SQL Server database. Here's a snippet of what I've...
2
2247
by: andycool1 | last post by:
I get the following error in my code when I set Option Strict to On: Option Strict On disallows implicit conversions from 'System.Object' to 'System.Drawing.Image' The blue error underline starts at "ResMan" and goes to the end of the line in this line of code: Dim i As System.Drawing.Image = ResMan.GetObject("logo.gif") ResMan is...
4
3632
by: Darrel | last post by:
I'm grabbing a file from a file upload form field. This is a 'system.web.httppostedfile' I would like to modify the image (Cropping/scaling) using system.drawing.image. Is there anyway to go from 'system.web.httppostedfile' directly to 'system.drawing.image'? Normally, I'd grab the System.Drawing.Image from a file itself:
3
8921
by: J | last post by:
I tried to inherit 'Shot' class from 'Image' class, only to fail. It gives me the CS0122 error, which says that it can't access 'System.Drawing.Image.Image()'. What am I missing? using System;
5
3358
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However, when I did this I got the following error: 'System.Drawing.Image.Image()' is inaccessible due to its protection level Looking at other online...
1
2694
by: Martijn Mulder | last post by:
At startup my application loads an image from a file from disk. If the file is not there, I still need a valid System.Drawing.Image object but I don't know how to get one. //class MyImage class MyImage { //data member image
3
6423
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating imagebuttons which point to a dummy page that takes the image and displays it via response. All works fine if I use explicit paths to a file...
0
8190
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8331
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
7940
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...
0
6590
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5705
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
3824
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
3850
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1441
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1163
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.