DataFlavor   article search result : 1

   // 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);
               return text;
           }
       } catch (UnsupportedFlavorException e) {
       } catch (IOException e) {
       }
       return null;
   }

Setting an image on the system clipboard requires a custom Transferable object to hold the image while on the clipboard.
   // This method writes a image to the system clipboard.
   // otherwise it returns null.
   public static void setClipboard(Image image) {
       ImageSelection imgSel = new ImageSelection(image);
       Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);
   }
  
   // This class is used to hold an image while on the clipboard.
   public static class ImageSelection implements Transferable {
       private Image image;
  
       public ImageSelection(Image image) {
           this.image = image;
       }
  
       // Returns supported flavors
       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
       public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
           if (!DataFlavor.imageFlavor.equals(flavor)) {
               throw new UnsupportedFlavorException(flavor);
           }
           return image;
       }
   }


크리에이티브 커먼즈 라이센스
Creative Commons License
2007/02/07 15:00 2007/02/07 15:00
tagged with  , ,
REPLY AND TRACKBACK RSS http://www.soulfree.net/rss/response/188
REPLY AND TRACKBACK ATOM http://www.soulfree.net/atom/response/188
TRACKBACK ADDRESS
http://www.soulfree.net/trackback/188
REPLY RSS http://www.soulfree.net/rss/comment/188
REPLY ATOM http://www.soulfree.net/atom/comment/188
이름 :
비밀번호 :
홈사이트 :
비밀글 :
*1 
count total 196425, today 347, yesterday 424
rss
I am
알립니다
전체
일상
영어공부
Hardware
Software
파일서버
지식 & 상식
Music, Movie, Game
Baseball & Lotte Giants
Soccer & Ulsan HyunDai
For A Foreign Visitor
프로그래밍및실험II
달력
«   2008/12   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31