Results 1 to 7 of 7
- 04-02-2011, 04:29 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
How do I scan a photo from my scanner into an ImageIcon object
I am writing a program that requires the user to scan a picture id of each customer that it enters into the database..
Right now I have the user scan the picture in and save it as a .jpg.. and then select from a list in the program.. then it saves it into the database..
I would like to make it so the user can place the id into the scanner and then when they press the button, it automatically scans the 2x3 area at the top left and saves it in an ImageIcon..
I'm using an HP Deskjet F2480 printer/scanner.
Any help would be greatly appreciated.
Regards.. Jeff.
- 04-02-2011, 05:13 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
Took a while to find, but, I'll start here..
Java Tech: Acquire Images with TWAIN and SANE, Part 3 | Java.net
- 04-02-2011, 05:48 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Thanks for posting that - it looks interesting.
- 04-03-2011, 06:19 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
Compiling JTwain.java, JTwainException.java w/err Can't find Symbol JTwainException
I have two files that I need to compile... however, I can't get JTwain.java to 'see' the file JTwainException.java
I am compiling on the command line at c:\code issuing the command:
javac net/javajeff/jtwain/JTwain.java
JTwain.java
JTwainException.java
they are in the folder c:\code\net\javajeff\jtwain.. I don't fully understand how the package name must match the file directory structure. It does match.. When I enter these files into NetBeans IDE and change the package name to the one that the IDE give's me, it compiles well..
I need to understand what's going on with the package... 'cause my next little nightmare in this is issuing the command:
javah net.javajeff.jtwain.JTwain.
Which is supposed to create a header file, (which of course doesn't work for me either.), that I need to compile a c++ prog to create jtwain32.dll..
Here are the contents.
I am relatively new to Java, however, I understand everything this prog does.
The package thing is slaying me though.
This code can be found at: http://today.java.net/today/2005/04/11/code.zip
/**
* JTwain.java
*/
package net.javajeff.jtwain;
import java.awt.Image;
/**
* This class provides the "glue" to connect the Java side of JTWAIN to the
* C++ side. Methods exist to initialize JTwain and interact with TWAIN.
*
* @author Jeff Friesen
*/
public class JTwain
{
/**
* Initialize JTwain. Initialization succeeds if System.loadLibrary() is
* able to find the jtwain library, if the jtwain library is able to find
* TWAIN_32.DLL, and if TWAIN_32.DLL contains the DSM_Entry() function. A
* messagebox is displayed if either TWAIN_32.DLL or DSM_Entry() can't be
* found.
*
* IMPORTANT: This method must be called before any other method. If this
* method returns false, do NOT call any other method.
*
* @return true if JTwain successfully initialized, otherwise false
*/
public static boolean init ()
{
try
{
System.loadLibrary ("jtwain");
return true;
}
catch (UnsatisfiedLinkError e)
{
return false;
}
}
/**
* Display the default source's dialog box to let the user configure that
* source. If the user clicks the Scan button, acquire one image from the
* default source.
*
* @return Image that describes the acquired image, otherwise null if the
* user clicked the Cancel button on the default source's dialog box
*
* @throws JTwainException if something goes wrong
*/
public static native Image acquire () throws JTwainException;
/**
* Select a source name from the source manager's dialog box. If the user
* clicks the Ok button, the highlighted source name becomes the new
* default source.
*
* @throws JTwainException if something goes wrong
*/
public static native void selectSourceAsDefault () throws JTwainException;
}
/**
* JTwainException.java
*/
package net.javajeff.jtwain;
/**
* This class defines the exception that is thrown from various places in the
* jtwain.dll code when some kind of failure occurs.
*
* @author Jeff Friesen
*/
public class JTwainException extends Exception
{
/**
* Construct a JTwainException object with the specified message.
*
* @param message a message that describes jtwain.dll code failure
*/
public JTwainException (String message)
{
super (message);
}
}
- 04-03-2011, 07:49 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
What happens when you try:
Java Code:c:\code>javac -cp . net\javajeff\jtwain\JTwain.java
From your description the exception class is in exactly the right place. The line given above includes the "-cp ." which sets the classpath to the current directory. The idea is that package names should match directory names starting from some place on the classpath.
- 04-03-2011, 08:53 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 21
- Rep Power
- 0
Ty.. It worked!
Compile worked well.. and I was able to create the header files and compile the c++ code for the jtwain.dll...
However, getting a twain not supported error..
Here is a demo of part of the program that I am current working on.
YouTube - Customer Entry Demo
- 05-09-2013, 08:51 AM #7
Member
- Join Date
- May 2013
- Posts
- 1
- Rep Power
- 0
Re: How do I scan a photo from my scanner into an ImageIcon object
Regarding your requirement, I have enclosed a sample for your reference. This sample is based on Microsoft SQL Server. But it is the same for other databases.
To use the sample, please follow the below steps.
1. You need to install Microsoft SQL server and a TWAIN scanner if you don't have it.
2. Set up a new database for the application.
3. Run the app in Visual Studio.
4. Click "Scan" -> "Upload" to save image in DB
5. Click "Load" to show it in the buffer
You said you were able to create the header files and compile the c++ code for the jtwain.dll.
I'm glad to here that.
Congratulations!
Cheers,
ArronLast edited by arronlee; 05-09-2013 at 08:54 AM.
Similar Threads
-
Problem Of Scanner Object with its method nextLine()
By Cluster Storm in forum AWT / SwingReplies: 12Last Post: 06-17-2010, 05:40 PM -
Photo Editing
By stekun in forum Advanced JavaReplies: 3Last Post: 02-23-2010, 05:11 AM -
Why do I need to declare a new Scanner object here?
By Chase in forum New To JavaReplies: 3Last Post: 09-24-2008, 11:59 PM -
Problems passing a scan object to a method
By xkross in forum New To JavaReplies: 4Last Post: 04-16-2008, 03:56 PM -
Regarding Scanner Object -- Cannot Resolve the Symbol
By pascal45 in forum New To JavaReplies: 1Last Post: 12-21-2007, 11:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks