Effects combine and save!

I have a small graphics programm, where I can rotate the picture and the change the brightness
in the JMenu "Edit".
I can also save these changes, but with the restriction that only one of the two will be saved. So if I rotate it and then set the brightness, the image jumps to the old position back. For brightness, it is exactly the same thing in reverse.
But now i want both, to rotate the image and change the image brightness. And save it.
It would be nice if someone could help me.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorConvertOp;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Grafikprogramm extends JFrame {
     private JMenuItem opennow;
     private JMenuItem close;
     private JMenuItem save;
     private JMenuItem quit;
     private JFileChooser fileChooser;
     private JMenuItem brightness;
     private JMenuItem rotate ;
     private JMenu menuBearbeiten;
     private JFrame f = new JFrame("Test");
     private File datei;
     private BufferedImage image;
     private BufferedImage originalImage;
     private JPanel unten;
     ViewComponent view = new ViewComponent(); // Layer with the picture
     private JSlider slider;
     private JSlider slider1;
     private JSlider slider2;
     private int centerX, centerY;
     Grafikprogramm() {
          super();
          Container content = getContentPane();
          this.setTitle("Bildbearbeiter");
          // MenuBar with Shortcuts
          JMenuBar menuLeiste = new JMenuBar();
          JMenu menuDatei = new JMenu("File");
          menuDatei.setMnemonic('D');
          menuBearbeiten = new JMenu("Edit");
          menuBearbeiten.setMnemonic('B');
          // Shortcuts Menu Aktionen
          opennow = new JMenuItem("Open", KeyEvent.VK_O);
          close = new JMenuItem("Close Picture", KeyEvent.VK_S);
          quit = new JMenuItem("Quit Program ", KeyEvent.VK_P);
          save = new JMenuItem("Save", KeyEvent.VK_S);
          opennow.addActionListener(new MenueAktion01());
          quit.addActionListener(new MenueAktion01());
          close.addActionListener(new MenueAktion01());
          save.addActionListener(new MenueAktion01());
          //Panel for Slider south
          unten = new JPanel();
          add(unten,BorderLayout.SOUTH);
          unten.setLayout(new GridLayout(4,1));
          unten.add(slider = new JSlider(1,50,25));
          unten.add(slider1 = new JSlider(1,50,25));
          unten.add(slider2 = new JSlider(1,50,25));
          slider.setVisible(false);
          slider1.setVisible(false);
          slider2.setVisible(false);
          // File selection for jpg and gif
          fileChooser = new JFileChooser();
          FileNameExtensionFilter filter = new FileNameExtensionFilter("Bildformate gif+jpg", "gif","jpg");
          fileChooser.setAcceptAllFileFilterUsed(false);
          fileChooser.addChoosableFileFilter(filter);
          menuDatei.add(opennow);
          menuDatei.add(close);
          menuDatei.add(save);
          menuDatei.add(quit);
          menuLeiste.add(menuDatei);
          menuLeiste.add(menuBearbeiten);
          this.setJMenuBar(menuLeiste);
          brightness = new JMenuItem("Brightness", KeyEvent.VK_H);
          rotate = new JMenuItem ("Rotate",KeyEvent.VK_D);
          menuBearbeiten.add(brightness);
          menuBearbeiten.add(rotate);
          brightness.addActionListener(new MenueAktion01());
          rotate.addActionListener(new MenueAktion01());
          close.setEnabled(true);
          menuBearbeiten.setEnabled(false);
          // window for the picture
          add(view);
     class ViewComponent extends JComponent {
          int width,height;
          public void setImage(File file) {
               try {
                    image = ImageIO.read(file);
                    repaint();
                    width = image.getWidth(null);
                    height = image.getHeight(null);
                    originalImage =
                         new BufferedImage(width, height,
                         BufferedImage.TYPE_INT_RGB);
                 Graphics g = originalImage.createGraphics();
                 g.drawImage(image, 0, 0, null);
                 g.dispose();
               catch (IOException e) {
                    JOptionPane.showMessageDialog(f, e.getMessage(), "Error",
                              JOptionPane.ERROR_MESSAGE);
          public void paint(Graphics g) {
               if (image != null) {
                    // if the image is load you can edit it
                    menuBearbeiten.setEnabled(true);
                    save.setEnabled(true);
                    Graphics2D g2d = image.createGraphics();
               } else {
                    g.drawString("No Picture load", 280, 200);
                    //     slider.setVisible(false);
                    save.setEnabled(false);
               g.drawImage(image, 0, 0, null);
     // rotate method
     public void rotate(double multiple) {
          AffineTransformOp op = new AffineTransformOp(
          AffineTransform.getRotateInstance(multiple,
                        centerX,
                        centerY),
                AffineTransformOp.TYPE_BILINEAR);
                image =  op.filter(originalImage, null);
             repaint();
     // brightness method
     public void setBrightnessFactor(float multiple) {
           RescaleOp op = new RescaleOp(multiple, 0, null);
           image = op.filter(originalImage, null);
           repaint();
     // Aktionen for Menu Items
     class MenueAktion01 implements ActionListener {
          int result;
          public void actionPerformed(ActionEvent e) {
               if (e.getSource() == opennow) {
                    slider.setVisible(false);
                    result = fileChooser.showOpenDialog(null);
                    if (result == fileChooser.APPROVE_OPTION) {
                         datei = fileChooser.getSelectedFile();
                         System.out.println(fileChooser.getSize());
                         System.out.println(datei);
                         if (fileChooser.getWidth() > 100) {
                              view.setImage(datei);
                              opennow.setEnabled(false);
                              close.setEnabled(true);
               // Close Programmm
               if (e.getSource() == quit) {
                    System.exit(0);
               // close picture
               if (e.getSource() == close) {
                    image = null;
                    slider.setVisible(false);
                    menuBearbeiten.setEnabled(false);
                    opennow.setEnabled(true);
                    close.setEnabled(false);
                    save.setEnabled(false);
                    slider.setVisible(false);
                    slider1.setVisible(false);
                    slider2.setVisible(false);
                    repaint();
               // save MenuItem
               if (e.getSource() == save) {
                    slider.setVisible(false);
                    // new JFileChooser for save
                    JFileChooser fc = new JFileChooser();
                    int returnVal = fc.showSaveDialog(Grafikprogramm.this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                         datei = fc.getSelectedFile();
                    // write with ImageIO
                         try {
                              ImageIO.write(image, "jpg", datei);
                         } catch (IOException e1) {
                              e1.printStackTrace();
               // rotate
               if (e.getSource()== rotate) {
                    slider.setVisible(false);
                    slider1.setVisible(false);
                    slider2.setVisible(true);
                    rotate(0);
                    slider2.addChangeListener(new ChangeListener() {
                         public void stateChanged(ChangeEvent e) {
                              centerX = (int)originalImage.getWidth()/2;
                             centerY = (int)originalImage.getHeight()/2;
                              rotate((double) (slider2.getValue()- 25.5) /4);
               // brightness               
               if (e.getSource() == brightness){
                    slider1.setVisible(true);
                    slider.setVisible(false);
                    slider2.setVisible(false);
                    setBrightnessFactor(1);
                    slider.setVisible(false);
                    slider1.setVisible(true);
                    slider1.addChangeListener(new ChangeListener(){
                         public void stateChanged(ChangeEvent e){
                              setBrightnessFactor((float)(slider1.getValue())/25);
     public static void main(String[] args) {
          Grafikprogramm main = new Grafikprogramm();
          main.setLocation(135, 0);
          main.setSize(640, 480);
          main.setBackground(Color.WHITE);
          main.setVisible(true);
          main.setAlwaysOnTop(false);
          main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}

your problem is that your original image is being used each time you call a method, either rotate or brightness. in order to do both, you have to either have the method return the adjusted image and store it back in the original image, or make a new method that does both.
for example:
     public BufferedImage rotate(double multiple, BufferedImage image) {
          AffineTransformOp op = new AffineTransformOp(
          AffineTransform.getRotateInstance(multiple,
                        centerX,
                        centerY),
                AffineTransformOp.TYPE_BILINEAR);
                this.image =  op.filter(image, null);
             repaint();
                                   return this.image;
      }so when you call your method, you supply the original BufferedImage image as the second argument.
null

Similar Messages

  • Just got this program , i have tried to combine and save

    just got this program , i have tried to combine and save ,
    a note comes up the document could not be saved. there was problem reading this document .

    Hi Bill Eiserman,
    Could you please let me know whether you are signed up at "https://cloud.acrobat.com/" using your Adobe ID credentials.
    Try saving those files to a different location on your system and check.
    You might update the web browser to the latest version or try signing up using a different browser.
    Let me know.
    Regards,
    Anubha

  • Best Way to Export After Effects File and Save Transparency

    Hi all-
    A pretty simple question. I need to export a file from After Effects and keep the alpha channel so I can superimpose it on some video in FCE. What is the best way to export it?
    I recall hearing people mention that the Animation Codec with "Millions of Colors+" is the best way to go about doing it, in which case I'd just have to render it within FCE. Is that correct? If so, are there any other settings I should tweak to get a high quality file that will work with FCE?
    Thanks.

    Hi -
    Animation Millions+ will deliver an extremely high quality file with the alpha channel. You will need to render once in FC.
    Hope this helps.

  • I recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank"

    i recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank" and when i try to open it, i can't? I NEED HELP !

    Here is the download page

  • Why won't my combined file save as a pdf to my dropbox?

    I just signed up, combined two pdf's and it will not save as a pdf when i save to my dropbox, it won't even open.

    Hi Dawn,
    If you combine the files and save them to your local drive first, then copy to your Dropbox, does that work?
    -David

  • SAP Query (SQ01) - create and save queryies

    Hi Expert;
    We wanted to implement SAP query reporting (SQ01) tool, and already developed custom HR infoset and user groups and transported to QAS.  We experienced the problem that we can not directly "save" any queries in SQ01. We pretty much have the client opened up and set at "Changes without automatic recording".  But keep getting a "transport object create" dialog upon "save" query.  But in Adhoc (PQAH), we don't encounter same problem.    We wanted our users be able to create and save any queries directly without creating any local objects. Is there another setting that needs to be set? 
    Thanks for any information that you can provide.  Points will be awarded.
    Helen

    Hello Helen,
    in SQ01 you can save queries like in HR Ad Hoc Query (or Infoset query as it is called outside HR).
    However this is only possible in the "Standard Area" not in the "Global Area". However as Ad Hoc Query is based on the SQ0x basics it only hides this effect.
    If you are doing HR specifics you should consider the documetnation on the special HR switches:
    http://service.sap.com/~form/sapnet?_SHORTKEY=01200252310000076208&
    In general if you are new to the topic you should consider the courses BC407 for Query Basics and HR580 for reporting in HR.
    Also to get a feeling for the different types of reporting with the InfoSet Query you can look at the following documentation:
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/a8/2e7237a323427ee10000009b38f8cf/frameset.htm
    HR Reporting Tools -> Sap Query -> InfoSet Query -> Calling InfoSet Query.
    Or you can book a special training if you need a contact let me know your email adress
    Best regards,
    Michael

  • Extract All Embedded Files in All Folders and Save Each? Copy/Paste from PDF to Word?

    I have most of what I need here, but I’m missing 2 important pieces. 
    #1)  I want to copy/paste from all PDF files in a folder and paste the copied data into a single Word file. 
    It works fine if I have ONLY Word docs in my folder.  When I have PDF files and Word files, the contents of the Word files are copied in fine, but the contents of the PDF files seem to come in as Chinese, and there is no Chinese in
    the PDF, so I have no idea where that’s coming from.
    #2)  I want to extract all embedded files (in all my Word files) and save the extracted/opened file into the folder.  Some embedded files are PDFs and some are Excel files.
    Here the code that I’m working with now.
    Sub Foo()
    Dim i As Long
    Dim MyName As String, MyPath As String
    Application.ScreenUpdating = False
    Documents.Add
    MyPath = "C:\Users\001\Desktop\Test\" ' <= change this as necessary
    MyName = Dir$(MyPath & "*.*") ' not *.* if you just want doc files
    On Error Resume Next
    Do While MyName <> ""
    If InStr(MyName, "~") = 0 Then
    Selection.InsertFile _
    FileName:="""" & MyPath & MyName & """", _
    ConfirmConversions:=False, Link:=False, _
    Attachment:=False
    Dim Myshape As InlineShape
    Dim IndexCount As Integer
    IndexCount = 1
    For Each Myshape In ActiveDocument.InlineShapes
    If Myshape.AlternativeText = PDFname Then
    ActiveDocument.InlineShapes(IndexCount).OLEFormat.Activate
    End If
    IndexCount = IndexCount + 1
    Next
    Selection.InsertBreak Type:=wdPageBreak
    End If
    On Error Resume Next
    Debug.Print MyName
    MyName = Dir ' gets the next doc file in the directory
    Loop
    End Sub
    If this has to be done using 2 Macros, that’s fine. 
    If I can do it in 1, that’s great too.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Hi ryguy72,
    >>When I have PDF files and Word files, the contents of the Word files are copied in fine, but the contents of the PDF files seem to come in as Chinese, and there is no Chinese in the PDF, so I have no idea where that’s coming from.<<
    Based on the code, you were insert the file via the code Selection.InsertFile. I am trying to reproduce this issue however failed. I suggest that you insert the PDF file manually to see whether this issue relative to the specific file. You can insert PDF
    file via Insert->Text->Object->Text from file.
    If this issue also could reproduced manually, I would suggest that you reopen a new thread in forum to narrow down whether this issue relative to the specific PDF file or Word application.
    >> I want to extract all embedded files (in all my Word files) and save the extracted/opened file into the folder.  Some embedded files are PDFs and some are Excel files.<<
    We can save the embedded spreadsheet via Excel object model. Here is an example that check the whether the inlineshape is an embedded workbook and save it to the disk for you reference:
    If Application.ActiveDocument.InlineShapes(1).OLEFormat.ClassType = "Excel.Sheet.12" Then
    Application.ActiveDocument.InlineShapes(1).OLEFormat.DoVerb xlPrimary
    Application.ActiveDocument.InlineShapes(1).OLEFormat.Object.SaveAs "C:\workbook1.xlsx"
    Application.ActiveDocument.InlineShapes(1).OLEFormat.Object.Close
    End If
    And since the Word object model doesn't provide API to save the embedded PDF, I would suggest that you get more effective response from PDF support forum to see whether it supports automation. If yes, we can export the PDF as embedded spreadsheet like code
    absolve.
    Hope it is helpful.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Save as Reduced Size PDF and Save as Optimized PDF do not reduce the file size.  What gives?

    Save as Reduced Size PDF and Save as Optimized PDF do not reduce the file size.  What gives?  I used Acrobat 9 to do this for a long time.  I recently received new laptop loaded with with Acrobat 10 and it does not work the same.  I typically scan 8-10 pages of receipts, combine the files in Acrobat, and then optimize to reduce the size so I can upload with my expense report.  Typically, my files were reduced to 200-400 KB.  I have a 2 MB file that will not reduce at all.

    Bernd, thank you for your attempt to help but the option dialog windows do not contain the same options.  There are numerous other posts on this forum about this issue and there is no answer.  Clearly, there is an issue.  I have submitted this issue to our internal help desk.

  • How to edit i-tunes s.a. fade in, fade out, cut and save for burning CD ?

    How to edit i-tunes, s.a. fade in fade out, cut and save for burning CD.
    I was directed to this forum by i-tunes helpdesk. Can some give advise how I can process those additional features that are not available in i-tunes 8 ?
    Thanks.
    Kris.

    Hi
    iMovie'08 & 09 is not the best tools to do a DVD or a DiskImage (via iDVD) from.
    You use iDVD to do the DiskImage - but that's when the movie is done.
    You can't (at least I can't) do a diskimage first then put a movie into it.
    The movie has to be encoded eg .mpeg2 and that's including the rest of the DVD structure too.
    No body builds houses - roof first then the supporting walls to end with throwing
    in a basement as a last action.
    To do a Data-DVD (*not playable in a DVD-player*) is another story.
    Just insert the DVD disk and when asked select format.
    This makes a DVD-ROM and You can drop movies and other files into this but
    when burned (taken out) it's done (one time burn)
    Please elaborate on what You want to be the result.
    iMovie HD 6 and iDVD'08 or 09 is a very nice combination.
    Yours Bengt W

  • Ipad takes photo every time I close the cover of its case. When I close the cover - it really does take a picture and saves a photo. Luckly, it make a click, and pictures are seen in the photo album, and it does not appear to be forwarding.

    When I close the cover - it really does take a picture and saves a photo. Luckly, it make a click, and pictures are seen in the photo album, and it does not appear to be forwarding. It is just gobbling memory and annoying as I can only delete these pictures one at a time.

    It seems to take a picture of the counter top = I do not see the keyboard.
    I am wondering ....It may be a kids game app that takes pictures of the screen or out the back camera. I am starting to think it may just be a sound effect when placing the iPad on its screen. So many things that may be unrelated but coincedental. It started in May (the sound) and so did the multiple pictures - starting to think they are not related.
    Thanks for the quick tip on deleting multiple pictures.

  • Best way to modify a WMV file and save to computer

    I have a 200 MB WMV file for a 4 hour meeting presentation.  I want to split it up and save it into 4 separate 1 hour presentations.  With a little editing in the middle to remove breaks and downtimes. 
    I can do everything but the Save.  Whenever I save it, it either is in really poor quality and 50 MB or it is okay quality and 500-5000 MB.  Quality doesn't have to be great but I should be able to read 12 point text when expanding it to full screen.
    How do I get my final copy to be of equal quality as the original and proportionallly small file size.

    I agree with Steve. While WMV is a supported format, the CODEC's used will initially heavily-compress the footage, and require some intense horsepower to internally convert to that DV-AVI.
    Were I faced with your Project, WMM would be my first stop. If I needed Effects, or more editing capabilities, then I would convert that WMV to DV-AVI externally, Import that, but would probably Export/Share to DV-AVI, and use the free MS Media Encoder (name just recently changed, so my link no longer works with for the new version), as PrE (and PrPro) is not the ultimate WMV Encoder.
    Remember, your material is already heavily-compressed, and no amount of conversion, whether internally, or externally, will recover the lost data and quality. Keeping things in WMV with WMM will keep it as good as it gets, and that is why Steve, and I, recommend it for this sort of Project. WMV's are great for delivery, but heck to edit.
    Good luck,
    Hunt

  • How to calculate and save planning data in bex input-ready query using keyfigures for calculation from different infoproviders

    Hi Dear All,
    We have two real time infocubes and two aggregation levels based on these cubes in one multiprovider
    first cube1 is like
    char1| char2| keyfig_coefficient(single value for each combination of char1 and char2)
    same aggregation level1
    (we have input query to fill coefficients by one responsible user)
    second cube2 is like
    char1| char2| keyfig_quantity| keyfig_result
    same aggregation level2
    Input ready query should be like (for all other users of different org units)
    char1|char2|keyfig_coeff| keyfig_quant(for input) | keyfig_result = keyfig_coeff*keyfig_quant(calculated value, should be saved to cube2)
    And we don't have pregenerated lines in cube2, users have to add new lines themselves by wad.
    Question is, what is the optimal (easiest) way to make calculation and save result data to cube2 where keyfigures for calculation should be used from different infoproviders. I need just a hint.
    Appreciate any help.
    Nadya.

    I found decision, agregation levels sould be based on multiprovider, not included.

  • Clip effects drag and drop?

    Hello folks. I'm evaluating a switch from Pro Tools to Audition on behalf of a production company. What I'm missing in Audition so far is the ability to quickly copy effetcs settings between clips/regions. For instance when a talking head reaperars now and then, I want to be able to use the same EQ setting that I made earlier. In Pro Tools you would typicly automate the EQ for each track and use the Write to all enabled parameters function, but in Audition clip effects seems to be the way to go. Other sound editors like Soundtrack and even video editors like FCP and Avid  let me drag the effect icon from one clip to another to apply the same effect whit the same  settings. And even save the settings by dragging the icon to a bin. I haven't found out how to do this in Audition, part from saving presets and loading them after having chosen the same effect onto the new clip, which if course is way to dodgy.
    Any quick reply would be appreciated.
    Thanks

    No it's not. Normally if you want to apply the same effect to a load of separate clips, you'd put them all on one track and apply the effects to that; it's a lot less processor-hungry doing it this way, as you only have to run one instance of the effect. Dragging the clips accurately is easy, and doing it like this means that you can see what's happening much more easily than if you have the clips all over the place (although it's a PITA not having grouping, admittedly). It all works fine when you're used to it - but it doesn't work the same way as PT does; if your production company wants to change, then they'll have to get used to a new way of working, I'm afraid.
    And I can't honestly say that Audition is ideal for doing this sort of stuff in its present release. Indeed, it may take a couple more versions before it gets to the sort of level that many people think it should be at. But I'm reasonably confident that it will. So my take on this at present is that it's fine to evaluate the present release - but only really in terms of its overall usability and way of doing things. It's not really fair to evaluate it in terms of overall features, because they're not all there yet.
    Oh, and there isn't anything dodgy about saving effects presets and reusing them - that's what the facility is there for, and it works fine. The nice thing about it is that you can apply several effects to a clip, and save the whole lot as one preset - rather better than having to save each preset's settings individually.

  • Effects in and out points

    I'm working with Soundtrack version 2.0.2. In previous versions, when adding an effect to a channel - you could hit the "down arrow" on the track to reveal the volume and pan, etc, etc and the effect showed up as a purple line there that you could insert points (like adjusting volume) and take the effect in and out at as you wanted in certain parts of an audio file. That option is not in this version evidently - can anyone tell me how to insert points to activate and deactivate effects so they come in a certain times and don't just affect the whole track?

    Do you use any time-stretching/ time remapping? Also this behavior may occur with some combinations of source timecode usage, so turn that off in the prefs and elsewhere if you don't depend on it...
    Mylenium

  • Increment and Save command

    The "Increment and Save" command in After Effects serves the fundamental need in professional creative work of preserving the various development stages of a job. Cinema 4D and other pro software packages also have this. Illustrator should too.

    Autosaviour Pro auto saves your Adobe Illustrator artwork
    and they have incremental backups.

Maybe you are looking for