tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
1554
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Registriert seit
    Jun 2002
    Ort
    Saarbrücken (Saarland)
    Beiträge
    9.886
    Blog-Einträge
    29
    Hallo!

    Hier mal ein kleines Beispiel zur Erstellung von Screenshots der Oberflaeche einer
    SWT Anwendung anhand einer Eclipse-Action.
    Code java:
    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    
    package de.tutorials.eclipse.screencapture.actions;
     
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.jface.viewers.ISelection;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.graphics.GC;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.graphics.ImageData;
    import org.eclipse.swt.graphics.ImageLoader;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.ui.IWorkbenchWindow;
    import org.eclipse.ui.IWorkbenchWindowActionDelegate;
     
    public class CreateScreenShotAction implements IWorkbenchWindowActionDelegate {
        private IWorkbenchWindow window;
        /**
         * The constructor.
         */
        public CreateScreenShotAction() {
        }
     
        /**
         * The action has been activated. The argument of the
         * method represents the 'real' action sitting
         * in the workbench UI.
         * @see IWorkbenchWindowActionDelegate#run
         */
        public void run(IAction action) {
            final Display display = Display.getDefault();
            Rectangle rectangle = display.getBounds();
            Image image = new Image(display,rectangle.width,rectangle.height);
            GC gc = new GC(display);
            gc.copyArea(image, 0,0);
            ImageLoader imageLoader = new ImageLoader();
            imageLoader.data = new ImageData[]{image.getImageData()};
            imageLoader.save("c:/screenShot.jpg", SWT.IMAGE_JPEG);
            image.dispose();
            gc.dispose();
            
            MessageDialog.openInformation(
                    window.getShell(),
                    "Screencapture Plug-in",
                    "Screenshot created");
        }
     
        /**
         * Selection in the workbench has been changed. We 
         * can change the state of the 'real' action here
         * if we want, but this can only happen after 
         * the delegate has been created.
         * @see IWorkbenchWindowActionDelegate#selectionChanged
         */
        public void selectionChanged(IAction action, ISelection selection) {
        }
     
        /**
         * We can use this method to dispose of any system
         * resources we previously allocated.
         * @see IWorkbenchWindowActionDelegate#dispose
         */
        public void dispose() {
        }
     
        /**
         * We will cache window object in order to
         * be able to provide parent shell for the message dialog.
         * @see IWorkbenchWindowActionDelegate#init
         */
        public void init(IWorkbenchWindow window) {
            this.window = window;
        }
    }

    Gruss Tom
     
    Java rocks!
    How to become a good Java Programmer?
    Does IT in Java and .Net
    The only valid measurement of code quality: WTFs / minute
    Blog
    Xing
    Twitter

  2. #2
    franklin216 franklin216 ist offline Grünschnabel
    Registriert seit
    Mar 2006
    Beiträge
    1
    Auch wenn es nach fünf Jahren ein wenig spät kommt. Muß es in der run-Methode nicht

    gc.copyArea(image, rectangle.x, rectangle.y);

    heißen um die aktive Anwendung zu bekommen?

    Trotzdem ein tolles Beispiel.
     

Ähnliche Themen

  1. Antworten: 5
    Letzter Beitrag: 20.11.09, 13:11
  2. Screenshots
    Von Kurama im Forum Videoschnitt, Videotechnik & -produktion
    Antworten: 1
    Letzter Beitrag: 06.07.04, 23:31
  3. screenshots erstellen
    Von Tosso im Forum VisualStudio & MFC
    Antworten: 3
    Letzter Beitrag: 06.07.04, 10:04
  4. Von DVD Filmen screenshots erstellen
    Von Andrew im Forum Videoschnitt, Videotechnik & -produktion
    Antworten: 6
    Letzter Beitrag: 15.12.02, 17:49
  5. screenshots
    Von brina im Forum Photoshop
    Antworten: 18
    Letzter Beitrag: 20.02.02, 13:03