Saving individual slices as images

I am creating a Website that has a tab with different names on each page.  When I save the slice individually, I would like to be able to save it to overwrite an old file.  If I'm not using slices, it just lets me do that.  How do I do that when I'm using a slice?  Whatever I do, the slice takes on its own name and when I have a huge amount of tabs to save, it would be nice just to save it to the old file name thus updating the old file.

OK, I get what you're on about, and I've tried that, but then the slice still doens't overwrite the old filenames.  For instance, the one I've shown in my example is the contact page.  Then I have a tab  with about us, testimonials, etc.  Then, of course, all those files have their own names such as aboutUs.jpg, testimonials.jpg, etc.  I want to be able to save that slice under all the different image names when I change the text.

Similar Messages

  • Problems saving individual slices

    Hi all. I've searched this forum for answers but I haven't found my specific question(s). If there is a thread that already exists, feel free to point me to it.
    Qualifier: I'm new to web design and using Photoshop to generate web graphics. I am, however, an experienced designer, not new to PS, but primarily use it for image manipulation and color correction of photos for print. The point is, being a newbie to this aspect of using PS, I may be asking it to do something it can't. I'd be interested in reading about best practices.
    I'm using Photoshop CS3, v.10.0.1.
    Background info: I have created a simple graphic for a splash page with a large logo in the middle, some text, and some navigation. The navigation has 1 rollover state. I have sliced the entire image, with the nav words being their own individual slices. Each nav word has a drop shadow and a color overlay effect applied to it. I saved the entire graphic's slices (with the nav words effects hidden) via the Save for Web & Devices dialog, choosing save HTML and images. Open the HTML file in DW, all is grand.
    So, now I have gone back into my PS file and shown the effects for the nav words. I want to save only those slices, with different names (i.e. _over appended to the name).
    So, two things:
    1: when saving, it creates a new folder every time, called Images, inside the Images folder that I've already pointed it to. Needless to say, it's creating massive confusion for my newbie brain. If I'm not mistaken, I want to have only one Images folder per web site. I guess there's some preference somewhere that I've failed to address. Please advise.
    2: When trying to save an individual slice, via the Save for Web and Devices dialog, even though I have only one slice selected, it still wants to save all the slices (I think). (Nothing is grayed out when that one slice is selected, as others have noted in other posts.) And, even though I rename the slice in the save dialog box, it still gives me a message that it's going to overwrite the original slice, which makes me think that it's ignoring my instructions to save it as a new name...
    I am gasping in frustration here. Any advice will be greatly appreciated, thank you.
    --Dina

    Buko--thank you! Jeez, I thought I was losing it with all the nested Images folders. So I assume if I uncheck that box on the Saving Files dialog that says to save it in a specific folder, it will let me assign where to save it. What about naming conventions? Should I change the default in the Slices dialog, or the Saving Files dialog?
    JMaloney: Hmmm. I will try that, although I don't see how it's different from what I have been doing... What is the difference between All Slices and Selected Slices? (besides the obvious) If I have one slice selected, and save All Slices, doesn't it still save all the slices in the image, as opposed to just All the Selected Slices? (jeez, I have forgotten what it's like when you don't know jack.)
    Thank you both!

  • Saving individual 3D pie chart slices

    I want to create an animated pie chart...with individual slices appearing one at a time.  I will do the actual annimation outside of Illustrator (likely in Flash or Motion).  The question is...after making a pie chart, can I save each slice as an individual graphic within Illustrator CS4?  Thanks in advance.

    Yes you can create an art board for each slice you can pull them apart with the direct select tool.
    You can the export them as individual files in a variety of ways.
    However this is the kind of thing you can do straight from Illustrator by releasing the art to a layers to a sequence and exporting as a swf and bring that into flash. You can also choose the option to save the Illustrator layers as flash symbols and simply import that file to the Flash Library.

  • How do I slice an image for a web banner and upload it to my website?

    Hi there! I am trying to slice an image into a web banner to upload it as the headed to my website layout. I have previously done this before, but a few months ago my computer crashed and I lost everything. I have a new computer now (Macbook Pro running 10.9.3) and downloaded a free trial of CS6. I vaguely remember what I am doing but am apparently way out of practice.
    I have tried at least a dozen different times to slice the banner and add the links, but for one, it keeps showing up with gaps in the image when I try and preview it on my computer. I cannot figure out why. Secondly, when I try to save it for the web as HTML and images, it is not working. It keeps saying something about needing to replace targets, etc. I am honestly lost and when I had originally made my website two years ago I don't remember it being nearly this difficult. I have some moderate HTML/CSS web design skills but I'm not sure if I am having a brainfart or what.
    Secondly, I cannot get the files to upload properly to my web server. I use FatCow as my host if this makes any difference. I've been watching tutorials on Youtube and trying to refresh my memory but I am so lost.
    Thanks!

    Can you save images via Tools > Page Info > Media ?
    The usual way to save an image is via the right-click context menu > Save Image as.<br />
    If you have a Mac without a right mouse button then see:
    * http://kb.mozillazine.org/ui.click_hold_context_menus

  • How can I drag an image from a page in Safari to the finder and have it be saved as an *actual* image instead of a webloc?

    Safari used to let me drag an image from a webpage to the finder and have the dragged file be saved as an actual image but now all that's saved is a webloc file.  I want the image saved, not a reference to the image's URL - do I now have to always use "save as" to save it?
    I can understand Safari creating a webloc file if I dragged the site icon from the location bar to the finder, but to make the default behavior for dragging things that are parts of a page (not the page itself) as webloc files seems like a HUGE step backwards for usability.
    Does anyone know if there's, say, a key to hold when dragging to avoid saving a webloc file or a defaults command or something to make Safari revert back to sane draging behavior?

    Good questions...  I'll have to try and figure out when the problem first happened - I was thinking it was when I upgraded to Safari 5.1.4 but that might not be the case...  I'll try your suggestions to see if any of them eliminate the problem (I have restarted recenlty and that didn't fix it) but I'll try repairing permissions,etc.  Thanks!
    hmmm... Mcbuffy: are you implying that you *don't* get the webloc when dragging an image out of Safari and that this isn't a caused by change to Safari but is a big/conflict in mine?

  • Preview "this layered Photoshop file was not saved with a composite image" error message?

    hi, i get this message:
    in preview, when i try to open a .psd file by double-clicking it:
    "this layered Photoshop file was not saved with a composite image"
    is there any program that will open this file, that came with my new iMac?
    OS 10.9.5
    thanks!
    ps. when i clicked all through help on my Mac, it would not tell me what i needed to know.
    So, is this forum the best way to find actual useful info?

    Thank you Chris,for the correct  answer - Best, Bob

  • When saving iDVD to disk image the following message appears: "Error during rendering/codification. There was an error during rendering/codification of menus/slide presentation. The recording process was canceled.

    When saving iDVD to disk image the following message appears: "Error during rendering/codification. There was an error during rendering/codification of menus/slide presentation. The recording process was canceled.
    What am I doing wrong?

    Read and answer the questions posted by Bengt Wärleby in this thread: Cant burn my idvd project to...: Apple Support Communities
    OT

  • How do I block individual pictures or images (not entire sites)

    .
    how do I block individual pictures or images (not entire sites) ?
    ------- '''SOLVED''' ------

    Someone told me to download 'adblock plus' It did the trick and more. I recommend it to everyone. Bill

  • Vertical repeating background slice from image

    Hi. I'm trying to slice a portion of a Photoshop CS4 image and use it as a vertical repeating background at the top of a web page. Then I'm overlaying the full image in the horizontal center of the web page. No matter how much I try, the background slice image comes out a little washed out compared to the full image -- with a slight border to each slice.
    What am I doing wrong? I've tried saving the image slice as GIF, JPG, and PNG, but they all produce the same result. Thanks.

    I had the slice set to 2px wide. Once I zoomed in very close, I could see that the right pixel was lighter than the left one all the way down the slice. I had feather set to 0 and it still did this. I sliced it down to 1px and that fixed it.

  • Saving a series of images (from a smart camera) into an AVI file

    Hello,
    I have a lab setup in which we view brain cell deflections in a well-plate after being pressurized with air for 50ms. I have a smart camera hooked up to an IMAQ PCI card to acquire images.
    I'm trying to save the series of images into an avi file, so that I can view the deflections in a slow video.
    The way I have it set up at the moment takes an image and saves it in an avi pre-existing (some random .avi that I didn't need) format. But here are some problems:
    1. I would like for the VI to create a NEW .avi, rather than saving it into a pre-existing one.
    2. Right now, each image simply overwrites the previous one in the avi file. So the resulting avi is a 00:00 length movie with a single image (the last frame that camera viewed).
    I have what I have programmed attached. Any help would be appreciated.
    Thank you,
    B.J. Kim
    University of Michigan
    Solved!
    Go to Solution.
    Attachments:
    forum.jpg ‏1438 KB

    Here is an updated version (attached). I kept trying to incorporate the examples you showed me, and I have made a little bit of a progress.
    It now saves a new avi file, and it's not a single image movie anymore. It's got as many images as I run the VI for. BUT, it only saves the very first image the camera takes and just loops it over and over again until I press stop. So the resulting avi shows a still image of the very first view of the camera for however long I ran the VI for.
    Any suggestions on how I can fix this?
    Thank you,
    B.J.
    Attachments:
    forum2.jpg ‏1190 KB

  • Why do the file extensions (.jpg .gif .png) no longer appear when I click on a previously saved image to use that image's file name (particularly important when saving a series of images using the same root name)?

    I save a lot of images using firefox, often times from a large batch or series of images. It used to be that I would click on a previously saved image and the entire file name including the file extension (i.e. image_example.jpg) would appear in the "save as" line. Now when I click on a previously saved file, the file name appears without the file extension (i.e. image_example). Which means I have to manually type .jpg every time. For a large collection of images that I am hoping to use the same root file name and then add chronological numbers at the end, this has become incredibly frustrating, especially as it is a previously unnecessary task.
    I am using a new Macbook Pro and maybe there's something Apple related to this...? It did not happen on my old PowerBook G4. I have file extensions turned on in System Preferences.
    It should be noted that I have searched high and low and have even gone into the Apple Genius Bar where they were just confused as I was and of course ended by urging me to use Safari (shocker!) as it has all kinds of new extensions and bells and whistles. I seriously feel alone on an island with this dumb, hard to google problem. Thanks so much for any help anyone out there might have.
    I mean: is this as simple as changing a setting in about:config?
    Your assistance is greatly appreciated.

    Thanks for your response Mylenium, however like I mentioned multiple times, I did change all of my trackpad/scrolling settings in system preferences.  And if I wanted to use a normal mouse (or a tablet), I would've gotten an iMac instead of a MacBook Pro.  I travel often and work all over the place, not always with access to a decently sized workspace that would be required for using a mouse or tablet.

  • Saving two dimensions od image for web

    Hi there,
    I have made script (with your help ) to export images for web with dimensions 300x300 px. Now I want that my script do one more resize of that files so that i get two files one 300x300 and another 66x66 px. I will post my script and ask you to hel me find the bug
    And one more question. My script exports file name + jpg but it also keeps orginal extension so I get ie. FileName.psd.jpg
    can you help me fixing this in my script... else is fine...
    thank you,
    Voah
    Edit:
    In the meen time I managed to resolve the problem so here is the new script
    But I have one more thing I would like to do. I have to manually make folder "300x300 and "66x66" or my script stops. How coud I make that script make that folders? (under inputFolder/300x300/ and inputFolder/66x66/)
    // Save current dialog preferences
    var startDisplayDialogs = app.displayDialogs;    
    // Save current unit preferences
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PIXELS;
    var inputFolder = Folder.selectDialog("Select the input folder");
    //var outputFolder = Folder.selectDialog("Select the output folder");
    ProcessImages();
    function ProcessImages() {
      var filesOpened = 0;
    //   if ( inputFolder == null || outputFolder == null)
         if ( inputFolder == null) {
                alert("No source folder selected");
    //     if ( outputFolder == null) {
    //       alert("No output folder selected");
    //else{
      var fileList = inputFolder.getFiles();
      for ( var i = 0; i < fileList.length; i++ ) {
           if ( fileList[i] instanceof File && ! fileList[i].hidden) {
                     open( fileList[i] );
                     ResizeImage();
                     filesOpened++;
      return filesOpened;
    function ExportPng(filePrefix, fileSuffix){
    try
    var docRef = app.activeDocument;
    var docName = app.activeDocument.name.slice(0,-4);
    var saveOptions = new ExportOptionsSaveForWeb();
    saveOptions.quality = 70;
    saveOptions.format = SaveDocumentType.JPEG;
    saveOptions.optimized = true;
    docRef.exportDocument(File(app.activeDocument.path+'/300x300//'+docName+'.jpg'), ExportType.SAVEFORWEB, saveOptions);
    catch (e)
    alert("Error encountered when attempting to save the image. \r\r" + e);
    return;
    // funkcija export 2
    function ExportPng2(filePrefix, fileSuffix){
    try
    var docRef = app.activeDocument;
    var docName = app.activeDocument.name.slice(0,-4);
    var saveOptions = new ExportOptionsSaveForWeb();
    saveOptions.quality = 70;
    saveOptions.format = SaveDocumentType.JPEG;
    saveOptions.optimized = true;
    docRef.exportDocument(File(app.activeDocument.path+'/66x66//'+docName+'.jpg'), ExportType.SAVEFORWEB, saveOptions);
    catch (e)
    alert("Error encountered when attempting to save the image. \r\r" + e);
    return;
    function ResizeImage()
    if (app.documents.length > 0) {
        var docRef = app.activeDocument;
        var n = docRef.pathItems.length;
            if((n>0)&&(docRef.pathItems[0].name!="Work path" ))  {
                 docRef.pathItems[0].makeSelection();
                 docRef.selection.invert();
                 docRef.selection.clear();
                 docRef.selection.deselect();
       function fitImage() {
    var docRef = app.activeDocument;
    docRef.trim()
    var docWidth = docRef.width.as("px");
    var docHeight = docRef.height.as("px");       
    if (docWidth / docHeight > 4.8)
        docRef.rotateCanvas (315)
        docRef.trim()
    else if (docHeight / docWidth > 4.8)
        docRef.rotateCanvas(45)
        docRef.trim()
    if (docWidth < docHeight)
              docRef.resizeImage(undefined, UnitValue(270,"px"), 72,  ResampleMethod.BICUBIC )
          else if (docWidth > docHeight)
                          docRef.resizeImage(UnitValue(270,"px"),undefined, 72,  ResampleMethod.BICUBIC )
          else if (docWidth == docHeight)
                    docRef.resizeImage(UnitValue(270,"px"),UnitValue(270,"px"), 72,  ResampleMethod.BICUBIC )
    docWidth = docRef.width.as("px");
    docHeight = docRef.height.as("px");       
    if (docWidth < docHeight)
                        docRef.resizeCanvas(UnitValue(300,"px"), UnitValue(300,"px"), AnchorPosition.MIDDLECENTER);
          else if (docWidth > docHeight)
                docRef.resizeCanvas(UnitValue(300,"px"), UnitValue(300,"px"), AnchorPosition.MIDDLECENTER);
          else if (docWidth == docHeight)
                docRef.resizeCanvas(UnitValue(300,"px"), UnitValue(300,"px"), AnchorPosition.MIDDLECENTER);
    var docRef = app.activeDocument;
    var savedState = docRef.activeHistoryState;
    fitImage();
    app.displayDialogs = DialogModes.NO;
    ExportPng( File( "",".jpg" ))
    docRef.resizeImage(UnitValue(66,"px"),UnitValue(66,"px"), 72,  ResampleMethod.BICUBIC );
                ExportPng2( File( "",".jpg" ))
    docRef.close(SaveOptions.DONOTSAVECHANGES);
    docRef = null;
    // Reset app preferences
    app.displayDialogs = startDisplayDialogs;
    preferences.rulerUnits = originalRulerUnits;

    Does this help?
    main();
    function main(){
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PIXELS;
    var inputFolder = Folder.selectDialog("Select the input folder");
    if(inputFolder == null) return;
    var fileList = inputFolder.getFiles(/\.(jpg|tif|psd|png)$/i);
    var outputFolder1 = Folder(inputFolder + "/300x300");
    if(!outputFolder1.exists) outputFolder1.create();
    var outputFolder2 = Folder(inputFolder + "/66x66");
    if(!outputFolder2.exists) outputFolder2.create();
    for (var a in fileList){
    open(fileList[a]);
    var Name = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
    app.activeDocument.trim(TrimType.TRANSPARENT);
    FitImage(300,300);
    var saveFile = File(outputFolder1 + "/" + Name + ".jpg");
    SaveForWeb(saveFile,70);
    FitImage(66,66);
    var saveFile = File(outputFolder2 + "/" + Name + ".jpg");
    SaveForWeb(saveFile,70);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    preferences.rulerUnits = originalRulerUnits;
    function FitImage( inWidth, inHeight ) {
    var desc = new ActionDescriptor();
    var unitPixels = charIDToTypeID( '#Pxl' );
    desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
    desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
    var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );
    executeAction( runtimeEventID, desc, DialogModes.NO );
    function SaveForWeb(saveFile,jpegQuality) {
    var sfwOptions = new ExportOptionsSaveForWeb();
       sfwOptions.format = SaveDocumentType.JPEG;
       sfwOptions.includeProfile = false;
       sfwOptions.interlaced = 0;
       sfwOptions.optimized = true;
       sfwOptions.quality = jpegQuality;
    activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

  • A problem about saving the picture control'image in a child VI.

    i want to use 'export image' method to get a picture control'image,so ,i have a child VI to use method 'export image',and a main VI to using the child VI,but when i run the main VI,there is no image is saved on the disk ,but if i open the child VI'frontpanel,then,i run the main VI,the image is saved on the disk,i want to know the reason why i can not get the image,when i run the main vi without the child 'frontpanel or blockdiagram is opened.
    Solved!
    Go to Solution.
    Attachments:
    child.vi ‏11 KB
    main.vi ‏7 KB

    The behavior that Simon describes is not a hard and fast rule, and the Export Image method used to be a bit of an exception.  It would supposedly update the controls of unopened FPs that used the method.  Reality never quite matched what was described in the documentation if I recall.
    If you pore over the detailed help you discover that this method works fine in SubVIs with some controls and not others.  Look at the characteristic 'Loads the Front Panel Into Memory', for a Picture control it is 'No', for a Waveform Graph, for instance, it is 'Yes'.  Caveat:  Relying on this level of detail to be correct in the LV help is a bit risky.  Best to try it yourself.  Not loading the FP is a good hint that the method is not going to behave in a SubVI.
    As to the problem at hand, a Picture Indicator is an odd choice to me to use this method.  You have VIs in the Picture palette to convert pictures to image data and then export the image data to a PNG or JPG or BMP file directly.  Anything you would draw and then export could be exported directly without drawing.

  • Saving Individual Clips in Premiere Elements 11

    Hi all -
    In Adobe Premiere Elements 11, after cutting a large video clip into many smaller clips and then renaming them, how do you go about saving each individual clip, so I can easily edit them?  I feel like I've looked everywhere and can't seem to figure it out. 
    Thanks!!
    Jerry

    Jerry
    My first impression is cannot do. But, let me think about this.
    Two major tasks...
    a. Even if we could get the "grouped" video/audio into Project Assets with a copy/paste insert with ClipMate
    then the next challenge would be
    b. How do we get the Preview Window with the Set In and Set Out points to deal with a grouped rather than linked video audio. It will not do that when the grouped video and audio are on the Timeline....we could do non Preview Window trimming at the Timeline level
    Think it worthwhile to download ClipMate to see how far we would get for this purpose of
    a. generating segments of grouped video and audio?
    b. pasting them into Project Assets where they would function as source media in or out of folders there?
    I suspect this is going to go the old fashion way of exporting the segments to a file saved to the computer hard drive and then bringing those segments back into a grand project for the final export..
    ClipMate, I believe, is a Windows only program. What computer operating system are you running your Premiere Elements 11 on?
    More later.
    ATR

  • Load, crop and saving jpg and gif images with JFileChooser

    Hello!
    I wonder is there someone out there who can help me with a applic that load, (crop) and saving images using JFileChooser with a simple GUI as possible. I'm new to programming and i hope someone can show me.
    Tor

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.filechooser.FileFilter;
    public class ChopShop extends JPanel {
        JFileChooser fileChooser;
        BufferedImage image;
        Rectangle clip = new Rectangle(50,50,150,150);
        boolean showClip = true;
        public ChopShop() {
            fileChooser = new JFileChooser(".");
            fileChooser.setFileFilter(new ImageFilter());
        public void setClip(int x, int y) {
            clip.setLocation(x, y);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(image != null) {
                int x = (getWidth() - image.getWidth())/2;
                int y = (getHeight() - image.getHeight())/2;
                g2.drawImage(image, x, y, this);
            if(showClip) {
                g2.setPaint(Color.red);
                g2.draw(clip);
        public Dimension getPreferredSize() {
            int width = 400;
            int height = 400;
            int margin = 20;
            if(image != null) {
                width = image.getWidth() + 2*margin;
                height = image.getHeight() + 2*margin;
            return new Dimension(width, height);
        private void showOpenDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    image = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("Read error for " + file.getPath() +
                                       ": " + e.getMessage());
                    image = null;
                revalidate();
                repaint();
        private void showSaveDialog() {
            if(image == null || !showClip)
                return;
            if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                String ext = ((ImageFilter)fileChooser.getFileFilter()).getExtension(file);
                // Make sure we have an ImageWriter for this extension.
                if(!canWriteTo(ext)) {
                    System.out.println("Cannot write image to " + ext + " file.");
                    String[] formatNames = ImageIO.getWriterFormatNames();
                    System.out.println("Supported extensions are:");
                    for(int j = 0; j < formatNames.length; j++)
                        System.out.println(formatNames[j]);
                    return;
                // If file exists, warn user, confirm overwrite.
                if(file.exists()) {
                    String message = "<html>" + file.getPath() + " already exists" +
                                     "<br>Do you want to replace it?";
                    int n = JOptionPane.showConfirmDialog(this, message, "Confirm",
                                                          JOptionPane.YES_NO_OPTION);
                    if(n != JOptionPane.YES_OPTION)
                        return;
                // Get the clipped image, if available. This is a subImage
                // of image -> they share the same data. Handle with care.
                BufferedImage clipped = getClippedImage();
                if(clipped == null)
                    return;
                // Copy the clipped image for safety.
                BufferedImage cropped = copy(clipped);
                boolean success = false;
                // Write cropped to the user-selected file.
                try {
                    success = ImageIO.write(cropped, ext, file);
                } catch(IOException e) {
                    System.out.println("Write error for " + file.getPath() +
                                       ": " + e.getMessage());
                System.out.println("writing image to " + file.getPath() +
                                   " was" + (success ? "" : " not") + " successful");
        private boolean canWriteTo(String ext) {
            // Support for writing gif format is new in j2se 1.6
            String[] formatNames = ImageIO.getWriterFormatNames();
            //System.out.printf("writer formats = %s%n",
            //                   java.util.Arrays.toString(formatNames));
            for(int j = 0; j < formatNames.length; j++) {
                if(formatNames[j].equalsIgnoreCase(ext))
                    return true;
            return false;
        private BufferedImage getClippedImage() {
            int w = getWidth();
            int h = getHeight();
            int iw = image.getWidth();
            int ih = image.getHeight();
            // Find origin of centered image.
            int ix = (w - iw)/2;
            int iy = (h - ih)/2;
            // Find clip location relative to image origin.
            int x = clip.x - ix;
            int y = clip.y - iy;
            // clip must be within image bounds to continue.
            if(x < 0 || x + clip.width  > iw || y < 0 || y + clip.height > ih) {
                System.out.println("clip is outside image boundries");
                return null;
            BufferedImage subImage = null;
            try {
                subImage = image.getSubimage(x, y, clip.width, clip.height);
            } catch(RasterFormatException e) {
                System.out.println("RFE: " + e.getMessage());
            // Caution: subImage is not independent from image. Changes
            // to one will affect the other. Copying is recommended.
            return subImage;
        private BufferedImage copy(BufferedImage src) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dest = new BufferedImage(w, h, src.getType());
            Graphics2D g2 = dest.createGraphics();
            g2.drawImage(src, 0, 0, this);
            g2.dispose();
            return dest;
        private JPanel getControls() {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(getCropPanel(), gbc);
            panel.add(getImagePanel(), gbc);
            return panel;
        private JPanel getCropPanel() {
            JToggleButton toggle = new JToggleButton("clip", showClip);
            toggle.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    showClip = ((AbstractButton)e.getSource()).isSelected();
                    repaint();
            SpinnerNumberModel widthModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner widthSpinner = new JSpinner(widthModel);
            SpinnerNumberModel heightModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner heightSpinner = new JSpinner(heightModel);
            ChangeListener cl = new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    JSpinner spinner = (JSpinner)e.getSource();
                    int value = ((Number)spinner.getValue()).intValue();
                    if(spinner == widthSpinner)
                        clip.width = value;
                    if(spinner == heightSpinner)
                        clip.height = value;
                    repaint();
            widthSpinner.addChangeListener(cl);
            heightSpinner.addChangeListener(cl);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            panel.add(toggle, gbc);
            addComponents(new JLabel("width"),  widthSpinner,  panel, gbc);
            addComponents(new JLabel("height"), heightSpinner, panel, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc) {
            gbc.anchor = GridBagConstraints.EAST;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(c2, gbc);
        private JPanel getImagePanel() {
            final JButton open = new JButton("open");
            final JButton save = new JButton("save");
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JButton button = (JButton)e.getSource();
                    if(button == open)
                        showOpenDialog();
                    if(button == save)
                        showSaveDialog();
            open.addActionListener(al);
            save.addActionListener(al);
            JPanel panel = new JPanel();
            panel.add(open);
            panel.add(save);
            return panel;
        public static void main(String[] args) {
            ChopShop chopShop = new ChopShop();
            ClipMover mover = new ClipMover(chopShop);
            chopShop.addMouseListener(mover);
            chopShop.addMouseMotionListener(mover);
            JFrame f = new JFrame("click inside rectangle to drag");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(chopShop));
            f.getContentPane().add(chopShop.getControls(), "Last");
            f.pack();
            f.setLocation(200,100);
            f.setVisible(true);
    class ImageFilter extends FileFilter {
        static String GIF = "gif";
        static String JPG = "jpg";
        static String PNG = "png";
        // bmp okay in j2se 1.5+
        public boolean accept(File file) {
            if(file.isDirectory())
                return true;
            String ext = getExtension(file).toLowerCase();
            if(ext.equals(GIF) || ext.equals(JPG) || ext.equals(PNG))
                return true;
            return false;
        public String getDescription() {
            return "gif, jpg, png images";
        public String getExtension(File file) {
            String s = file.getPath();
            int dot = s.lastIndexOf(".");
            return (dot != -1) ? s.substring(dot+1) : "";
    class ClipMover extends MouseInputAdapter {
        ChopShop component;
        Point offset = new Point();
        boolean dragging = false;
        public ClipMover(ChopShop cs) {
            component = cs;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            if(component.clip.contains(p)) {
                offset.x = p.x - component.clip.x;
                offset.y = p.y - component.clip.y;
                dragging = true;
        public void mouseReleased(MouseEvent e) {
            dragging = false;
        public void mouseDragged(MouseEvent e) {
            if(dragging) {
                int x = e.getX() - offset.x;
                int y = e.getY() - offset.y;
                component.setClip(x, y);
    }

Maybe you are looking for

  • HELP!! I'm trying to purchase a gift for someone in app world and it won't work!!

    I received a gift request for an app in Blackberry App World and I am tryi g desperately to accept it but all I get is "please wait" it is driving me crazy. I was able to buy one once before and had the same problems but after deleting app world, reb

  • Fields in Report

    Hello,     I need fields for following reports. Fields for Purchase orders Report. Fields  for Plant and Purchase Organization with all the vendors of the selected material. Fields for Customer Sales report, which gives complete information of sales

  • Imac sound from web site

    my imac won't play the sound embedded in a web site. i know the speakers work cause a cd plays ok. i think it is just when accessing a web site (i use safari). what am i missing?

  • Add-on available in tool option

    well i protected the addon option using pulic fox but the add-on r available in toolbar i want to protect my children visiting the add-on option?

  • SNP Keyfigure Explaination

    Hi All, Where can I find a document which explains how the SNP keyfigures are calculated Eg; Stock on hand =( Planned Reciept + stock from R/3 +  production planned or ,,,) Supply Shortage = Total Demand-Total Reciept-stocks Thanks Ravi