Writing Image in the clipboard to Oracle DB

Hi,
I want to write the image in the clipboard to the Blob am using JDeveloper. Can any1 help me please I am stuck on conversion and writing to Blob.
Very Urgent Please!!!!!!!
Comments: Applet is used to diplay an image present in the clipboard, convert this image into bytes write it to a blob and transfer the blob into Oracle DB
package mypackage1;
import java.applet.Applet;
import javax.swing.JLabel;
import oracle.jdeveloper.layout.XYLayout;
import oracle.jdeveloper.layout.XYConstraints;
import java.awt.datatransfer.*;
import java.awt.image.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.event.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import oracle.jdeveloper.layout.OverlayLayout2;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Blob;
import java.sql.Statement;
import java.awt.Toolkit;
import java.awt.event.*; //Clipboard
import java.awt.datatransfer.*; //Clipboard
import java.awt.Image;// .image.*; //Clipboard
import java.sql.*;
import java.sql.*;
import java.net.*;
import java.lang.*;
import java.awt.TextField;
import java.awt.Font;
import oracle.sql.BLOB;
public class ClipboardImage extends Applet
Button displayButton = new Button();
Button exitButton = new Button();
JLabel photoLabel = new JLabel();
Panel panel1 = new Panel();
XYLayout xYLayout2 = new XYLayout();
XYLayout xYLayout1 = new XYLayout();
Button submitButton = new Button();
Connection connection = null;
static Image photo;
public byte[] data;
public Blob bl;
TextField Message = new TextField();
public ClipboardImage()
public void init()
try
jbInit();
catch(Exception e)
e.printStackTrace();
public static void main(String[] args)
ClipboardImage applet = new ClipboardImage();
Frame frame = new Frame();
frame.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
frame.add(applet, BorderLayout.CENTER);
frame.setTitle("Applet Frame");
applet.init();
applet.start();
frame.setSize(300, 300);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((d.width - frameSize.width) / 2, (d.height -
frameSize.height) / 2);
frame.setVisible(true);
private void jbInit() throws Exception
this.setLayout(xYLayout2);
this.setBackground(new Color(136, 212, 122));
displayButton.setLabel("Display");
displayButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
scanButton_actionPerformed(e);
exitButton.setLabel("Exit");
exitButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
exitButton_actionPerformed(e);
photoLabel.setText("Photo");
panel1.setLayout(xYLayout1);
panel1.setBackground(new Color(255, 249, 240));
xYLayout2.setWidth(288);
xYLayout2.setHeight(300);
submitButton.setLabel("Submit");
submitButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
submitButton_actionPerformed(e);
Message.setFont(new Font("Abadi MT Condensed", 0, 9));
panel1.add(photoLabel, new XYConstraints(0, 0, 115, 155));
this.add(Message, new XYConstraints(20, 275, 250, 15));
this.add(submitButton, new XYConstraints(105, 220, 80, 30));
this.add(panel1, new XYConstraints(90, 25, 115, 155));
this.add(exitButton, new XYConstraints(195, 220, 85, 30));
this.add(displayButton, new XYConstraints(10, 220, 85, 30));
void exitButton_actionPerformed(ActionEvent e)
System.exit(0);
If an image is on the system clipboard, this method returns it
otherwise it returns null
public static Image getClipboard()
Transferable t =
Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try
if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor))
Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
photo = text;
return text;
catch (UnsupportedFlavorException e)
catch (IOException e)
return null;
Display an image in the system's clipboard
void scanButton_actionPerformed(ActionEvent e)
Image img = this.getClipboard();
photo = img;
photoLabel.setIcon(new ImageIcon(photo));
// Gives out int array
public int[] fetchPixels(Image image, int width, int height)
int pixMap[] = new int[width*height];
PixelGrabber pg = new PixelGrabber(image, 0,0,width,height, pixMap,
0, width);
try
pg.grabPixels();
catch (InterruptedException e)
return null;
if((pg.status() & ImageObserver.ABORT)!=0)
return null;
return pixMap;
// Here int array given by Pixel Grabber function is converted into
byte array
public byte[] extractData(int[] pixmap, int numbands) {
byte data[] = new byte[pixmap.length*numbands];
for(int i=0;i<pixmap.length;i++){
int pixel = pixmap;
byte a = (byte)((pixel >> 24) & 0xff);
byte r = (byte)((pixel >> 16) & 0xff);
byte g = (byte)((pixel >> 8) & 0xff);
byte b = (byte)((pixel ) & 0xff);
if(numbands == 4){
data[i*numbands+0] = r;
data[i*numbands+1] = g;
data[i*numbands+2]= b;
data[i*numbands+3] = a;
} else {
data[i*numbands+0] = r;
data[i*numbands+1] = g;
data[i*numbands+2]= b;
return data;
public void processData() {
Image awtImage = getClipboard();
int imageWidth = awtImage.getWidth(this);
int imageHeight = awtImage.getHeight(this);
int[] pix = fetchPixels(awtImage, imageWidth, imageHeight);
data = extractData(pix, 4);
photo = awtImage;
System.out.println(" Height = " + imageHeight + " Width = " +
imageWidth + " Pixel = " + pix + " Byte = " + data);
void submitButton_actionPerformed(ActionEvent e)
processData();
try {
System.out.println("Executing code");
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "10.20.90.101";
String portNumber = "1521";
String sid = "iasdb";
String url = "jdbc:oracle:thin:@" + serverName + ":" +
portNumber + ":" + sid;
String username = "birmingham";
String password = "in";
connection = DriverManager.getConnection(url, username,
password);
PreparedStatement ast = connection.prepareStatement("INSERT
INTO PASSPORT (PASSID, PHOTO) VALUES (1992, EMPTY_BLOB())");
ast.executeUpdate();
PreparedStatement pst = connection.prepareStatement("UPDATE
PASSPORT SET PHOTO = ? WHERE PASSID = 1992");
//pst.setObject(1, (Object)photo);
//Writing bytes to blob bl
bl.setBytes(0, data);
//Setting the blob to transfer to the blob column in oracle
db
pst.setBlob(1, bl);
pst.executeUpdate(); if(pst.EXECUTE_FAILED == 1)
Message.setText("Sql failed!");
}else{
Message.setText("Sql success!");
System.out.println ("Connected\n");
} catch (ClassNotFoundException ea) {
// Could not find the database driver
} catch (SQLException ea) {
System.out.println(ea.toString());

Look at the ArrayListTransferHandler class in the following Drag List Demo example: http://www.java2s.com/Code/Java/Swing-JFC/DragListDemo.htm

Similar Messages

  • Copy ImageField Images to the clipboard

    We've created ImageFields in a pdf to for people to send into us.
    However we would like to be able to take those images and copy and paste them into other things. emails for example.
    right now the ImageField only lets you click it to add an image. We can't select or right click that image to copy it to the clipboard.
    is there a way to setup a button or something that via javascript or some other way allow us to copy that image to the clipboard?

    Hi,
    to copy an image to the clipboard you can use the snapshopt tool from Acrobats or Readers Edit menu.
    There is no other way I'm afraid.

  • I want to copy an image to the clipboard in firefox using firefox clipboard API

    I Want to copy an image to the clipboard using firefox clipboard API.
    Please let me know he steps

    Thanks for the reply, but I want to copy the IMAGE to the clipboard programmatically in javascript using firefox clipboard API.
    For ex using the following syntax:
    var clip = Components.classes'@mozilla.org/widget/clipboard;1']
    I am able to copy the text, but I don't know the syntax to copy the IMAGE.

  • Copy and paste a image to the clipboard

    Hi,
    Is there anybody who knows how to copy and paste an image to the clipboard in jdk 1.3.0.
    I want make a image copy of my app like this (Panel):
    Image image = (Image)this.createImage(this.getWidth(), this.getHeight());
    Graphics g = image.getGraphics();
    this.paint(g);
    BufferedImage bufImage = (BufferedImage)image;
    Now i will send this bufImage or the image to the clipboard.
    How will it works?
    Thanks a lot.

    Hi,
    I m having similar type of problem but with JPanel not with image. i m able to copy paste a JPanel using same clipboard but i want some more operations like after zoomin my JPanel , i want that now if i copy the image of Jpanel it should be the copy of original size of JPanel not the zoomed one but in my application it is showing the blank picture
    for zoom fit size of JPanel its working ok.
    please advice me what should i do

  • How to save a new jpg image from the clipboard

    It seems like it should be simple but I can't find anywhere this has been documented.
    I have an image on the clipboard and simply want to save it as a new image.
    I've been using Image Events and I can get a file saved but it's always empty.
    Can someone please post some sample code to do this?

    I'm sure there's a more elegant way to script this, but here is a script I just wrote real quick that should at least give you a start to an alternate way of dealing with clipboard data without having to launch Preview...
    <pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
    title="Copy this code and paste it into your Script Editor application.">--see if clipboard is a file
    set filePath to ""
    try
    set clipPath to the clipboard as «class furl»
    set filePath to clipPath as alias
    end try
    if filePath is not "" then
    set newFile to getFileName("copied")
    do shell script "cp " & quoted form of POSIX path of filePath & ¬
    space & quoted form of POSIX path of newFile
    return --end
    end if
    --see if clipboard is image data
    set jpegDATA to ""
    try
    set jpegDATA to the clipboard as JPEG picture
    end try
    if jpegDATA is not "" then
    set newFile to getFileName("new")
    set theFile to open for access newFile with write permission
    write jpegDATA to theFile
    close access theFile
    return --end
    end if
    beep 1
    display dialog ¬
    "No file or image data found on the clipboard." with icon ¬
    note buttons {"Whatever"} default button 1
    on getFileName(type)
    choose file name with prompt ¬
    "Select a name and location for the " & type & ¬
    " jpeg:" default location (path to desktop) default name ¬
    type & ".jpg"
    end getFileName</pre>
    Hope this helps...

  • Writing text in the clipboard

    Hi,
    To write text in the clipboard the natural way is to use the StringSelection flavor. The problem is it requires a String to work on. But here I have a big volume (xml) that I generate from a DOM like structure => I would like to stream the generated xml in the clipboard without loading it in a String.
    Anybody knows if it is possible by writing a custom Data Flavor ?
    Thanks,
    Jean

    Look at the ArrayListTransferHandler class in the following Drag List Demo example: http://www.java2s.com/Code/Java/Swing-JFC/DragListDemo.htm

  • How can I erase images from the clipboard while using ink and slide or sketches and lines apps?

    I've been having trouble with my clipboard while using my adobe ink. Is there any way I can erase the images saved on the clipboard, because have been trying and I can't find a way to do it, it seems like the only option is by turning the selection into favorites and then a trashcan icon appears, but even if I choose delete it will only be erased from the clipboard favorites while remaining on the clipboard.
    I've thought erasing the sketches App, or deleting the project but I don't want to risk losing my work.
    Thanks!

    I posed a similar question in the Draw forum and got this reply:
    Re: How to clear the clipboard and empty drawings ?
    In short: you can't erase those clippings, at least not currently.

  • How to paste pictures, images from the clipboard

    Hey all,
    I've made a java-application and with a click on a button, I jump to a drawprogram.
    When I've finished my picture, copied it to the clipboard(ctrl c), I want to show it in my application.
    How can I do this and in which component must I paste it?
    Thanks

    There isn't a way to do it that is part of Lightroom. There is a plug-in that might help you, though. Check it out here: Locktastic
    It doesn't say if its compatible with LR4, but you can try it to find out.
    Plug-ins aren't usually as efficient as built-in functionality (like PM), but it might be a solution for you.

  • Paste is only pasting a text field instead of an image copied to the clipboard from another program like mail or safari?

    The latest version of Keynote only pastes a blank text field after copying an image to the clipboard in other applications like mail or Safari.  The previous version worked fine with copying and pasting images.  Saving the image to a file and then inserting the image file is the only work-a-round I have found so far.

    To place an image on a slide, use Finder to drag and drop the file onto the slide.

  • Pasting images that have been put onto the clipboard by other applications

    I have the following problem. Might be that I am just overlooking something but I haven't found any information or other java programs that would solve this problem.
    I want to access the System Clipboard and retrive images copied onto the System Clipboard by an other application (e.g. paint, irfanView, ... ). Copy and pasting works perfectly with Strings or Images I myself copied to the Clipboard, but as soon as I want to access an image from an other application clipboard.getContents(this) returns null as though the Clipboard was empty. (Where clipboard =getToolkit().getSystemClipboard();)
    I downloaded a couple of other java applications that handle images (e.g. ImageJ) and found out that those also can't paste images from other sources.
    Is there a way to do that? Has anybody found a solution for that or have I really overlooked something, and it's just one of those stupid bugs one never finds by oneself?

    Hi,
    this was exactly my problem. With "Copy and pasting works perfectly with Strings or Images I myself copied to the Clipboard" I mean that I copied the Images and Strings from within a Java Application on to the System Clipboard. It didn't work if the image came from another win32 application. I solved the problem by using JNI, reading the images from the clipboard using C++ and then passing an int[] array to the java application.

  • How to capture an image with the camera axis

    Hi,
    I have an camera axis. I can receive the video. Now I try to capture an image, for example when I push the button take. I do the .vi but I confused between the different Method.
    SaveCurrentImageave the current Image
    GetImage:Gets the data corresponding to the image currently being
    displayed.SetImage:Adds an Image to the Clipboard in the Bitmap format
    That I search is to know if to capture image and saving when I push an button  I need to put all Icons so SetImage after Getimage and SavecurrentImage.
    I put my .vi.  
    Attachments:
    Capture_image.vi ‏11 KB

    Hello,
    Did you download the kit sdkfor using the axis media control active X:
    http://www.axis.com/fr/techsup/cam_servers/dev/activex.htm
    Did you test the sample and did you test with another language?
    Regards,
    Nacer M. | Certified LabVIEW Architecte

  • Pasting Image  from Mac clipboard to Java Based Application.

    Hi,
    I am working on "iMac 10.2.7". I need to paste an image from other
    application using "Java version 1.4.1". I am trying to retrieve the image
    from the system clipboard after it is copied from some other application. I
    am pasting the code which illustrates my requirement. It works fine on
    windows. But does not work on Mac.
    On Mac it does not cross the supported data flavor check
    (clipData.isDataFlavorSupported(DataFlavor.imageFlavor) where clipData is
    the Transferable object). It seems Mac has some InputStream instead of Image
    in the clipboard when some image is copied. I tried to read that InputStream
    using ImageIO.read(java.io.InputStream). But that is also returning null.
    Thanks
    Santanu
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class ClipboardTest extends JFrame implements KeyListener{
         JLabel label;
         static Toolkit kit = null;
         static Clipboard clipboard = null;
         public static void main (String arg[]) {
              kit = Toolkit.getDefaultToolkit();
              clipboard = kit.getSystemClipboard();
              JLabel l = new JLabel();
              JButton button = new JButton("Paste from clipboard");
              final ClipboardTest ct = new ClipboardTest(l);
              ct.getContentPane().add(l,BorderLayout.CENTER);
              ct.getContentPane().add(button,BorderLayout.SOUTH);
              ct.setVisible(true);
         button.addActionListener(
              new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        pasteImage(ct.label);
         button.addKeyListener(ct);
         public ClipboardTest (JLabel l) {
              label = l;
         public static void pasteImage(JComponent jComp) {
                   jComp.setTransferHandler(new ImageSelection());
                   TransferHandler handler = jComp.getTransferHandler();
                   Transferable clipData = clipboard.getContents(null);
              if (clipData != null) {
              if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                   handler.importData(jComp, clipData);
         //Key listener methods
         public void keyPressed(KeyEvent e) {
         int c = e.getKeyCode();
         if (c == 86) {
              if (e.isControlDown()) {
                   pasteImage(label);
         public void keyReleased(KeyEvent e) {}
         public void keyTyped(KeyEvent e) {}
    class ImageSelection extends TransferHandler implements Transferable {
         /* DataFlavor instance that holds imageflavor value*/
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         private Image image;
         public boolean importData(JComponent comp, Transferable transferable) {
         try {
         if (transferable.isDataFlavorSupported(flavors[0])) {
         image = (Image)transferable.getTransferData(flavors[0]);
                   if (comp instanceof JLabel) {
                   ((JLabel)comp).setIcon(new ImageIcon(image));
                   comp.repaint();
                   return true;
         } catch (Exception ignored) {
              ignored.printStackTrace();
         return false;
         // Transferable Interface methods
         public Object getTransferData(DataFlavor flavor) {
         if (isDataFlavorSupported(flavor)) {
         return image;
         return null;
         public DataFlavor[] getTransferDataFlavors() {
         return flavors;
         public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.equals(flavors[0]);

    Here are two commercial options:
    JTwain + JSane
    http://asprise.com/product/jtwain/index.php
    Morena
    http://www.gnome.sk/Twain/jtp.html
    Haven't tested them, so don't no how good they are, nor how easy they are to use on multiple platforms.

  • Here's How to change the image on the TOC to be different for each chapter.

    Suppose you don't follow the Very Strict default Rule that you use the exact same image parameters (shape, pixels, size, etc.) for your Table of Contents image entry as you use for its associated Chapter, a requirement built in to iBooks Author that applies universally to ALL Chapters under the One Image Size and Location is Best For Everyone rule. Suppose you start adding chapters and messing with each chapter's image and then, later, it occurs to you to get the TOC all set up and when you go there you encounter a mess. Either by chance one of the images you had in one of your chapters found its way to the TOC and, gosh, now every TOC entry for every chapter has the very same exact size and location image! This is not part of your grand plan and then... how to make lemonade here? It's Not Obvious.
    You can resolve this in your favor. You must do this patiently.
    First, whatever image size is created in any chapter TOC window—by dragging the image placeholder handle re-size box—will apply to ALL image entries (i.e., chapter image entries) in the TOC . If you want maximum flexibility make the image placeholder box big. Hint: you may need to mess with the Edit Mask option in order to get the image placeholder size box in the size and location you want. An option here in preparing your images is to **** with Photoshop or Preview to really engineer the images that will be used for the Chapter Page and, separately, the TOC / these could be the same content images but formatted differently in order to look nice in their respective locations. The Chapter Page image can be manipulated on the Chapter Page. On the other hand, the TOC image must fit within whatever (universal) size you've created.
    Plan ahead
    Get your TOC images ready.
    Loop until done:
    a) from the Finder menu, right click on the filename of the image to be put in the TOC / select the menu item “Copy”..this image. This puts the image in the clipboard. Another way to get the image in the clipboard is to pull it up with Preview and pretend to crop it (full size) then command-C. Another way: just click on it if it is in a file somewhere and again command-C.
    b) Click on the Table of Contents option (near the top of the left navigation column in ibooks Author ) and navigate to the TOC chapter for this image by clicking on the correct chapter “button” (a white dot in a black background surrounded by a white rounded-corner box) in the center bottom of the TOC chapter window;
    c) Click on the image placeholder in this chapter TOC window to reveal the highlight boxes defining the boundary of the image;
    d)command-V (paste); Voila! the image is in the TOC. NOTE: dragging the image into the highlighted imagebox (see c) above) will NOT work.
    e) mess with the image by clicking the mask editor button so the image fits as desired being careful to move the image only and not resize the image box.
    Go back to loop and repeat.

    Finally, after a while, I finally found all the procedure explained,
    for those who need:
    http://www.irisvista.com/tech/laptops/ToshibaS1/tecraS1_1.htm

  • Cannot copy and paste images from the web into Corel Draw

    Attempting to copy and paste a jpg image from a client's website, for use in Corel Draw... Copy appears to work fine, and pasting into other programs like Windows Paint works, but paste to CorelDraw has no result.
    I've seen where others would get the text URL but nothing happens when I hit paste.
    Drag and drop imports the text name of the image.

    Since Firefox 13, when you copy an image, Firefox places both the image data (bitmap data) and the URL of the image on the clipboard. I can see why you would get one or the other, but I can't think of why you would get nothing.
    Did this just start in Firefox 22?
    Some odd interactions have been noted between Firefox 22 and ZoneAlarm: when ''copying'' selected text in Firefox, the clipboard may end up blank a significant percentage of the time . But it sounds as though you have a different issue.
    Do you have the same issue in Firefox's Safe Mode? That's a standard diagnostic tool to bypass interference by extensions (and some custom settings). More info: [[Troubleshoot Firefox issues using Safe Mode]].
    You can restart Firefox in Safe Mode using
    Help > Restart with Add-ons Disabled
    In the dialog, click "Start in Safe Mode" (''not'' Reset)
    Any difference?

  • 300dpi Image: copy to clipboard??

    Hi everybody,
    I have somewhat like a problem:
    I set up something like a picture album with director.
    Also there is a function to copy a selected image to the
    clipboard in order to import it into PowerPoint.
    Now, the original images have a resolution of 300dpi, but
    when I copy it to the clipboard, they turn out to have only 72dpi
    but HUGE dimensions.
    My question:
    - Is it possible at all for director to put JPGs into the
    Clipboard with a resoltion of 300dpi???
    - Is there an Xtra I could use for it?
    THANKS SO MUCH!!
    Jonas

        public static void writeToClipboard(Image image) {
            ImageSelection imageSelection =
                new ImageSelection(image);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imageSelection, null);
        public static class ImageSelection implements Transferable {
            // the Image object which will be housed by the ImageSelection
            private Image image;
            public ImageSelection(Image image) {
                this.image = image;
            // Returns the supported flavors of our implementation
            public DataFlavor[] getTransferDataFlavors() {
                return new DataFlavor[] {DataFlavor.imageFlavor};
            // Returns true if flavor is supported
            public boolean isDataFlavorSupported(DataFlavor flavor) {
                return DataFlavor.imageFlavor.equals(flavor);
            // Returns Image object housed by Transferable object
            public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,IOException {
                if (!DataFlavor.imageFlavor.equals(flavor)) {
                    throw new UnsupportedFlavorException(flavor);
                // else return the payload
                return image;
        }

Maybe you are looking for

  • Newbie question on report design for multiple pages - HELP!

    I am upgrading an existing accounting program to use Crystal reports. The accounting program generates account statements for our investors. Each account needs to have 1 statement (which typically is only 1 page long). I have a table that has 1 recor

  • How to get DocSet property values in a SharePoint library into a CSV file using Powershell

    Hi, How to get DocSet property values in a SharePoint library into a CSV file using Powershell? Any help would be greatly appreciated. Thank you. AA.

  • "Checking your addons for compatibility with this version of Firefox" hangs

    On one pc (but not others) running Windows 7, when I install a new version of FF and the box for "checking your addons etc" comes up, it gets 80% of the way through then just grinds away until I hit cancel. Is there any way to find outr which addon i

  • Calling executable file

    Hi all, I have made one classical report in which i am taking output in text file. Now for printing that text file i have made one BATCH File (Executable file of DOS). So is there any command to execute that batch file directly from my report? Thanks

  • Piping script line in a powershell script

    Hi, I would like piping informations in a powershell script and getting this: If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) $argum