├── Examples ├── ij.jar ├── plugin.jar ├── scanning.jar ├── twain.jar └── webScanning.html ├── JRE └── jre.exe ├── README ├── ScanningInterface ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── bin │ ├── ClipedPanel.class │ ├── java.policy.applet │ ├── scanning$1.class │ ├── scanning$2.class │ ├── scanning$ClipMover.class │ ├── scanning$ImagePanel$1.class │ ├── scanning$ImagePanel$2.class │ ├── scanning$ImagePanel$3.class │ ├── scanning$ImagePanel$4.class │ ├── scanning$ImagePanel$5.class │ ├── scanning$ImagePanel.class │ └── scanning.class ├── lib │ ├── ij.jar │ ├── plugin.jar │ └── uk.co.mmscomputing.device.twain.jar └── src │ └── scanning.java ├── Signed Jar's ├── ij.jar ├── plugin.jar ├── scanning.jar └── twain.jar └── Snapshots ├── 1.jpg └── 2.jpg /Examples/ij.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/Examples/ij.jar -------------------------------------------------------------------------------- /Examples/plugin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/Examples/plugin.jar -------------------------------------------------------------------------------- /Examples/scanning.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/Examples/scanning.jar -------------------------------------------------------------------------------- /Examples/twain.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/Examples/twain.jar -------------------------------------------------------------------------------- /Examples/webScanning.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /JRE/jre.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/JRE/jre.exe -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Project goal is to facilitate users to access connected Configured Scanners directly from web page. 2 | No Need to register or copy any DLL's at user side. It's a web based i.e. Java Applet web embedded. 3 | User is able to Scan,capture, crop and save images from a Scanner (all in web page) to his PC or to the configured remote server. 4 | 5 | Added prominent Live image cropping feature. 6 | 7 | Libraries Used: uk.co.mmscomputing.device.twain, ImageJ. 8 | 9 | For Executing: Check Examples Folder, run webScanning.html. 10 | 11 | Standalone Applet: Import entire code into myeclipse and run scanning.java class for executing the project. 12 | 13 | Web Page: Just Export this myeclipse code as a scanning.jar, Sign it and embed it in a web page as Java Applet invoking scanning.class (Include all ij.jar,plugin.jar,twain.jar along with scanning.jar in applet archive tag as signed jars). 14 | 15 | Pre-requisites: JAVA Enabled browser, JRE Installed 16 | -------------------------------------------------------------------------------- /ScanningInterface/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ScanningInterface/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ScanningInterface 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /ScanningInterface/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Tue Jun 05 12:05:16 IST 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /ScanningInterface/bin/ClipedPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/ClipedPanel.class -------------------------------------------------------------------------------- /ScanningInterface/bin/java.policy.applet: -------------------------------------------------------------------------------- 1 | /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ 2 | /* DO NOT EDIT */ 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$1.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$2.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ClipMover.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ClipMover.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel$1.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel$2.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel$3.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel$4.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel$5.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning$ImagePanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning$ImagePanel.class -------------------------------------------------------------------------------- /ScanningInterface/bin/scanning.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/bin/scanning.class -------------------------------------------------------------------------------- /ScanningInterface/lib/ij.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/lib/ij.jar -------------------------------------------------------------------------------- /ScanningInterface/lib/plugin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/lib/plugin.jar -------------------------------------------------------------------------------- /ScanningInterface/lib/uk.co.mmscomputing.device.twain.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishkataria/browserWebScanning/19a8e5c8ce8de5d27dad0ed1e973d6c3626e5eb1/ScanningInterface/lib/uk.co.mmscomputing.device.twain.jar -------------------------------------------------------------------------------- /ScanningInterface/src/scanning.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | Modified and Integrated cropping to scanner plugin for ImageJ which uses the free mm's computing java library 5 | (available at http://www.mms-computing.co.uk/) 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License 9 | as published by the Free Software Foundation; either version 2 10 | of the License, or (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ 20 | 21 | import ij.IJ; 22 | import ij.ImagePlus; 23 | import ij.gui.ImageCanvas; 24 | import ij.gui.Roi; 25 | import ij.plugin.PlugIn; 26 | 27 | import java.awt.BorderLayout; 28 | import java.awt.Color; 29 | import java.awt.Container; 30 | import java.awt.Dimension; 31 | import java.awt.FlowLayout; 32 | import java.awt.Graphics; 33 | import java.awt.Graphics2D; 34 | import java.awt.GridLayout; 35 | import java.awt.Image; 36 | import java.awt.Point; 37 | import java.awt.Rectangle; 38 | import java.awt.RenderingHints; 39 | import java.awt.ScrollPane; 40 | import java.awt.event.ActionEvent; 41 | import java.awt.event.ActionListener; 42 | import java.awt.event.MouseAdapter; 43 | import java.awt.event.MouseEvent; 44 | import java.awt.event.MouseMotionAdapter; 45 | import java.awt.image.BufferedImage; 46 | import java.awt.image.RasterFormatException; 47 | 48 | import javax.imageio.ImageIO; 49 | import javax.swing.JApplet; 50 | import netscape.javascript.*; 51 | 52 | 53 | import java.io.ByteArrayInputStream; 54 | import java.io.ByteArrayOutputStream; 55 | import java.io.File; 56 | import java.io.IOException; 57 | import java.io.InputStream; 58 | import java.io.ObjectInputStream; 59 | import java.io.ObjectOutputStream; 60 | import java.io.OutputStream; 61 | import java.net.MalformedURLException; 62 | import java.net.URL; 63 | import java.net.URLConnection; 64 | import java.sql.Connection; 65 | import java.sql.PreparedStatement; 66 | import java.sql.SQLException; 67 | import java.util.Vector; 68 | 69 | import javax.swing.BorderFactory; 70 | import javax.swing.ImageIcon; 71 | import javax.swing.JButton; 72 | import javax.swing.JCheckBox; 73 | import javax.swing.JComponent; 74 | import javax.swing.JFileChooser; 75 | import javax.swing.JFrame; 76 | import javax.swing.JLabel; 77 | import javax.swing.JOptionPane; 78 | import javax.swing.JPanel; 79 | import javax.swing.JScrollPane; 80 | import javax.swing.JSlider; 81 | import javax.swing.JToolBar; 82 | import javax.swing.SpringLayout; 83 | import javax.swing.SwingConstants; 84 | 85 | import uk.co.mmscomputing.device.scanner.Scanner; 86 | import uk.co.mmscomputing.device.scanner.ScannerDevice; 87 | import uk.co.mmscomputing.device.scanner.ScannerIOException; 88 | import uk.co.mmscomputing.device.scanner.ScannerIOMetadata; 89 | import uk.co.mmscomputing.device.scanner.ScannerListener; 90 | import javax.swing.WindowConstants; 91 | import javax.swing.border.LineBorder; 92 | import javax.swing.event.ChangeEvent; 93 | import javax.swing.event.ChangeListener; 94 | import javax.swing.event.MouseInputAdapter; 95 | import uk.co.mmscomputing.device.twain.TwainSource; 96 | import uk.co.mmscomputing.device.twain.TwainSourceManager; 97 | 98 | 99 | public class scanning extends JApplet implements PlugIn, ScannerListener 100 | { 101 | 102 | private JToolBar jtoolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL); 103 | ImagePanel ipanel; 104 | Image im =null; 105 | BufferedImage imageforCrop; 106 | ImagePlus imp=null; 107 | int imageWidth; 108 | int imageHeight; 109 | private static final long serialVersionUID = 1L; 110 | Container content = null; 111 | private JPanel jContentPane = null; 112 | private JButton jButton = null; 113 | private JButton jButton1 = null; 114 | JCheckBox clipBox = null; 115 | JPanel crpdpanel=null; 116 | JPanel cpanel=null; 117 | private Scanner scanner=null; 118 | TwainSource ts ; 119 | 120 | ImagePanel imagePanel,imagePanel2 ; 121 | 122 | 123 | 124 | 125 | public static void main(String[] args) { 126 | new scanning().setVisible(true); 127 | } 128 | 129 | public void run(String arg0) { 130 | 131 | new scanning().setVisible(false); 132 | repaint(); 133 | } 134 | 135 | /** 136 | * This is the default constructor 137 | */ 138 | public scanning() { 139 | super(); 140 | init(); 141 | try { 142 | scanner = Scanner.getDevice(); 143 | scanner.addListener(this); 144 | } catch (Exception e) 145 | { 146 | e.printStackTrace(); 147 | } 148 | 149 | 150 | } 151 | 152 | /** 153 | * This method initializes this 154 | * 155 | * @return void 156 | */ 157 | public void init() 158 | { 159 | this.setSize(1200, 600); 160 | this.setLayout(null); 161 | //this.revalidate(); 162 | this.setContentPane(getJContentPane()); 163 | } 164 | 165 | 166 | public void stop() 167 | { 168 | 169 | } 170 | 171 | public void destroy() 172 | { 173 | 174 | } 175 | 176 | 177 | public void start() 178 | { 179 | 180 | } 181 | 182 | 183 | private JToolBar getJToolBar() 184 | { 185 | jtoolbar.add(getJButton1()); 186 | jtoolbar.add(getJButton()); 187 | 188 | 189 | jtoolbar.setName("My Toolbar"); 190 | jtoolbar.addSeparator(); 191 | Rectangle r=new Rectangle(0, 0,1024, 30 ); 192 | jtoolbar.setBounds(r); 193 | jtoolbar.setBackground(Color.white); 194 | return jtoolbar; 195 | } 196 | 197 | private JPanel getJContentPane() 198 | { 199 | if (jContentPane == null) 200 | { 201 | jContentPane = new JPanel(); 202 | jContentPane.setLayout(null); 203 | jContentPane.setBackground(Color.white); 204 | jContentPane.add(getJToolBar()); 205 | } 206 | return jContentPane; 207 | } 208 | 209 | 210 | private JButton getJButton() { 211 | if (jButton == null) { 212 | jButton = new JButton(); 213 | jButton.setBounds(new Rectangle(4, 16, 131, 42)); 214 | jButton.setText("Select Device"); 215 | jButton.setBackground(Color.white); 216 | jButton.addActionListener(new java.awt.event.ActionListener() { 217 | public void actionPerformed(java.awt.event.ActionEvent e) { 218 | if (scanner.isBusy() == false) { 219 | selectDevice(); 220 | } 221 | 222 | } 223 | }); 224 | } 225 | return jButton; 226 | } 227 | 228 | 229 | /* Select the twain source! */ 230 | public void selectDevice() { 231 | 232 | try { 233 | scanner.select(); 234 | } catch (ScannerIOException e1) { 235 | IJ.error(e1.toString()); 236 | } 237 | 238 | } 239 | 240 | private JButton getJButton1() 241 | { 242 | if (jButton1 == null) { 243 | jButton1 = new JButton(); 244 | jButton1.setBounds(new Rectangle(35,0, 30, 30)); 245 | jButton1.setText("Scan"); 246 | jButton1.setBackground(Color.white); 247 | jButton1.addActionListener(new java.awt.event.ActionListener() { 248 | public void actionPerformed(java.awt.event.ActionEvent e) 249 | { 250 | getScan(); 251 | } 252 | }); 253 | } 254 | return jButton1; 255 | } 256 | 257 | public void getScan() 258 | { 259 | 260 | try 261 | { 262 | scanner.acquire(); 263 | } 264 | catch (ScannerIOException e1) 265 | { 266 | IJ.showMessage("Access denied! \nTwain dialog maybe already opened!"); 267 | e1.printStackTrace(); 268 | } 269 | } 270 | 271 | 272 | 273 | public Image getImage() 274 | { 275 | Image image = imp.getImage(); 276 | return image; 277 | } 278 | 279 | 280 | 281 | public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata) { 282 | 283 | 284 | 285 | if (type.equals(ScannerIOMetadata.ACQUIRED)) 286 | { 287 | 288 | if(imp!=null) 289 | { 290 | jContentPane.remove(ipanel); 291 | jContentPane.remove(cpanel); 292 | jContentPane.remove(crpdpanel); 293 | } 294 | 295 | 296 | imp = new ImagePlus("Scan", metadata.getImage()); 297 | 298 | im = imp.getImage(); 299 | 300 | imagePanel = new ImagePanel(im); 301 | imagePanel.updateUI(); 302 | 303 | imagePanel.repaint(); 304 | imagePanel.revalidate(); 305 | 306 | ClipMover mover = new ClipMover(imagePanel); 307 | imagePanel.addMouseListener(mover); 308 | imagePanel.addMouseMotionListener(mover); 309 | 310 | ipanel = imagePanel.getPanel(); 311 | 312 | ipanel.setBorder(new LineBorder(Color.blue,1)); 313 | ipanel.setBorder(BorderFactory.createTitledBorder("Scanned Image")); 314 | ipanel.setBounds(0, 30,600, 600); 315 | ipanel.repaint(); 316 | ipanel.revalidate(); 317 | ipanel.updateUI(); 318 | jContentPane.add(ipanel); 319 | jContentPane.getRootPane().revalidate(); 320 | jContentPane.updateUI(); 321 | 322 | cpanel = imagePanel.getUIPanel(); 323 | cpanel.setBounds(700, 30,300, 150); 324 | cpanel.repaint(); 325 | cpanel.setBorder(new LineBorder(Color.blue,1)); 326 | cpanel.setBorder(BorderFactory.createTitledBorder("Cropping Image")); 327 | cpanel.setBackground(Color.white); 328 | jContentPane.add(cpanel); 329 | 330 | 331 | jContentPane.repaint(); 332 | jContentPane.revalidate(); 333 | 334 | 335 | 336 | 337 | metadata.setImage(null); 338 | try { 339 | new uk.co.mmscomputing.concurrent.Semaphore(0, true).tryAcquire(2000, null); 340 | } catch (InterruptedException e) { 341 | IJ.error(e.getMessage()); 342 | 343 | } 344 | 345 | } 346 | 347 | 348 | 349 | 350 | else if (type.equals(ScannerIOMetadata.NEGOTIATE)) { 351 | ScannerDevice device = metadata.getDevice(); 352 | try { 353 | device.setResolution(100); 354 | } catch (ScannerIOException e) { 355 | IJ.error(e.getMessage()); 356 | } 357 | 358 | try{ 359 | 360 | device.setShowUserInterface(true); 361 | device.setResolution(100); }catch(Exception e){ 362 | e.printStackTrace(); } 363 | 364 | } 365 | 366 | 367 | else if (type.equals(ScannerIOMetadata.STATECHANGE)) { 368 | System.out.println("Scanner State "+metadata.getStateStr()); 369 | System.out.println("Scanner State "+metadata.getState()); 370 | 371 | if ((metadata.getLastState() == 3) && (metadata.getState() == 4)){} 372 | 373 | } else if (type.equals(ScannerIOMetadata.EXCEPTION)) { 374 | IJ.error(metadata.getException().toString()); 375 | 376 | } 377 | 378 | } 379 | 380 | 381 | 382 | class ImagePanel extends JPanel 383 | { 384 | private Image image; 385 | Image cimg; 386 | int imageWidth; 387 | int imageHeight; 388 | 389 | BufferedImage imageb; 390 | Dimension size; 391 | public Rectangle clip; 392 | boolean showClip,clipedImg; 393 | 394 | public boolean isShowClip() { 395 | return showClip; 396 | } 397 | 398 | 399 | JSlider slider1 = new JSlider(SwingConstants.HORIZONTAL, 80, 180, 80); 400 | 401 | ClipedPanel clipedPanel; 402 | 403 | ImagePanel(Image image) 404 | { 405 | this.image=image; 406 | this.imageWidth=image.getWidth(null); 407 | this.imageHeight=image.getHeight(null); 408 | this.imageb= (BufferedImage) image; 409 | size = new Dimension(imageb.getWidth(), imageb.getHeight()); 410 | showClip = true; 411 | 412 | } 413 | 414 | 415 | public Image getImage() 416 | { 417 | return image; 418 | } 419 | 420 | public Image getCimg() 421 | { 422 | return cimg; 423 | } 424 | 425 | 426 | 427 | protected void paintComponent(Graphics g) 428 | { 429 | super.paintComponent(g); 430 | Graphics2D g2 = (Graphics2D)g; 431 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 432 | RenderingHints.VALUE_ANTIALIAS_ON); 433 | int x = (getWidth() - size.width)/2; 434 | int y = (getHeight() - size.height)/2; 435 | 436 | 437 | g2.drawImage(imageb, x, y, this); 438 | if(showClip) 439 | { 440 | if(clip == null) 441 | createClip(80,80); 442 | g2.setPaint(Color.red); 443 | g2.draw(clip); 444 | } 445 | } 446 | 447 | 448 | public void setClip(int x, int y) 449 | { 450 | 451 | int x0 = (getWidth() - size.width)/2; 452 | int y0 = (getHeight() - size.height)/2; 453 | 454 | if(x < x0 || x + clip.width > x0 + size.width || 455 | y < y0 || y + clip.height > y0 + size.height) 456 | return; 457 | 458 | clip.setLocation(x, y); 459 | repaint(); 460 | 461 | clipImage(); 462 | repaint(); 463 | } 464 | 465 | public Dimension getPreferredSize() 466 | { 467 | return size; 468 | } 469 | 470 | private void createClip(int sx,int sy) 471 | { 472 | clip = new Rectangle(sx, sy); 473 | 474 | clip.x = (getWidth() - clip.width)/2; 475 | clip.y = (getHeight() - clip.height)/2; 476 | } 477 | 478 | public JPanel getCroppedPanel() 479 | { 480 | 481 | ClipedPanel cpanel = this.getClippedImg(); 482 | 483 | 484 | return cpanel; 485 | } 486 | 487 | 488 | private void clipImage() 489 | 490 | { 491 | BufferedImage clipped = null; 492 | try 493 | { 494 | int w = clip.width; 495 | int h = clip.height; 496 | int x0 = (getWidth() - size.width)/2; 497 | int y0 = (getHeight() - size.height)/2; 498 | int x = clip.x - x0; 499 | int y = clip.y - y0; 500 | clipped = imageb.getSubimage(x, y, w, h); 501 | 502 | 503 | cimg = clipped; 504 | 505 | clipedPanel = new ClipedPanel( cimg); 506 | 507 | crpdpanel = imagePanel.getCroppedPanel(); 508 | 509 | crpdpanel.setBounds(700, 200,300, 300); 510 | crpdpanel.repaint(); 511 | 512 | crpdpanel.setBorder(new LineBorder(Color.red,1)); 513 | crpdpanel.setBorder(BorderFactory.createTitledBorder("Cropped Image")); 514 | crpdpanel.setBackground(Color.white); 515 | 516 | jContentPane.add(crpdpanel); 517 | jContentPane.repaint(); 518 | jContentPane.revalidate(); 519 | 520 | } 521 | catch(RasterFormatException rfe) 522 | { 523 | System.out.println("raster format error: " + rfe.getMessage()); 524 | } 525 | 526 | } 527 | 528 | public ClipedPanel getClippedImg() 529 | { 530 | return clipedPanel; 531 | } 532 | 533 | 534 | 535 | public JPanel getUIPanel() 536 | { 537 | 538 | JButton clip = new JButton("Crop image"); 539 | clip.addActionListener(new ActionListener() 540 | { 541 | public void actionPerformed(ActionEvent e) 542 | { 543 | repaint(); 544 | if(getClippedImg()!=null) 545 | jContentPane.remove(getClippedImg()); 546 | if(showClip) 547 | { 548 | clipImage(); 549 | repaint(); 550 | clipedImg=true; 551 | 552 | } 553 | else 554 | { 555 | JOptionPane.showMessageDialog(null, "First Check Show clip Check Box!"); 556 | } 557 | 558 | } 559 | }); 560 | 561 | 562 | 563 | slider1.setPaintLabels(true); 564 | slider1.setPaintTicks(true); 565 | 566 | slider1.addChangeListener(new ChangeListener() 567 | { 568 | public void stateChanged(ChangeEvent e) 569 | { 570 | repaint(); 571 | 572 | int sx1 = slider1.getValue(); 573 | int sy1=slider1.getValue(); 574 | createClip( sx1, sy1); 575 | 576 | repaint(); 577 | if(getClippedImg()!=null) 578 | jContentPane.remove(getClippedImg()); 579 | 580 | if(isShowClip()) 581 | { 582 | clipImage(); 583 | repaint(); 584 | } 585 | else 586 | { 587 | JOptionPane.showMessageDialog(null, "First Check Show clip Check Box!"); 588 | } 589 | 590 | } 591 | }); 592 | 593 | JButton save = new JButton("Save image"); 594 | JButton upload = new JButton("Upload image"); 595 | JButton saveDoc = new JButton("Save Document (Without Cropping)"); 596 | 597 | upload.addActionListener(new ActionListener() 598 | 599 | { 600 | 601 | public void actionPerformed(ActionEvent e) { 602 | 603 | if(clipedImg) 604 | { 605 | //saveImg(); 606 | repaint(); 607 | if(getClippedImg()!=null) 608 | jContentPane.remove(getClippedImg()); 609 | } 610 | 611 | 612 | 613 | Image image=getCimg(); 614 | 615 | BufferedImage bufferedImage=new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); 616 | bufferedImage.createGraphics().drawImage(image, 0, 0, null); 617 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 618 | try { 619 | ImageIO.write(bufferedImage, "png", baos); 620 | } catch (IOException e1) { 621 | e1.printStackTrace(); 622 | } 623 | InputStream is = new ByteArrayInputStream(baos.toByteArray()); 624 | JOptionPane.showMessageDialog(null, "Server Settings need to be Configured.", "Upload Image",1); 625 | 626 | }} 627 | 628 | ); 629 | 630 | 631 | save.addActionListener(new ActionListener() 632 | { 633 | public void actionPerformed(ActionEvent e) 634 | { 635 | 636 | 637 | if(clipedImg) 638 | { 639 | 640 | repaint(); 641 | if(getClippedImg()!=null) 642 | jContentPane.remove(getClippedImg()); 643 | } 644 | 645 | 646 | saveImg(); 647 | 648 | } 649 | }); 650 | 651 | 652 | 653 | 654 | saveDoc.addActionListener(new ActionListener() 655 | { 656 | public void actionPerformed(ActionEvent e) 657 | { 658 | repaint(); 659 | 660 | 661 | saveDoc(); 662 | repaint(); 663 | 664 | } 665 | 666 | 667 | }); 668 | 669 | 670 | 671 | 672 | JPanel panel = new JPanel(); 673 | //panel.add(clipBox); 674 | panel.add(clip); 675 | panel.add(slider1); 676 | slider1.setBackground(Color.white); 677 | panel.add(save); 678 | panel.add(upload); 679 | panel.add(saveDoc); 680 | panel.revalidate(); 681 | return panel; 682 | } 683 | 684 | 685 | 686 | 687 | 688 | public void saveImg() 689 | { 690 | 691 | Image image=getCimg(); 692 | 693 | BufferedImage bufferedImage=new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); 694 | bufferedImage.createGraphics().drawImage(image, 0, 0, null); 695 | JFileChooser chooser=new JFileChooser(); 696 | 697 | 698 | String e[] = ImageIO.getWriterFormatNames(); 699 | for (int i=0; i