Saving and redrawing image from stack

Hi ,
I have a small problem with images...I create BufferedImage which i save on stack everytime i click on a mouse button , but when i try to reacall that image from stack i dont get nothing or the last Image i made.
This is the short description of my prog. :
I have a main class that extends JFrame and inner class that extends JPanel and has a mouse listener , ... in this inner class everytime i press a mouse button i send image on stack , and problems i have is when i press a button declared in my main class to pop image from stack and paint it on my inner JPanel class i dont know how to implement this.
So if anyone can help...please doooo

I appologise...everytime i pasted code i forgot to change something...small tweeks...but now it work I tried it...before it didnt compile cos of small tweeks...but now it woks...I hope u ll see my problem when i hit undo button...everything is gone...maybe i need to create a new image to send on stack or something and load that image when i hit undo button...i dont know???
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
public class PainterDemo extends JFrame implements ActionListener{
       Stack stack=new Stack();
       BufferedImage image=new                                     BufferedImage(400,400,BufferedImage.TYPE_4BYTE_ABGR);
       Graphics graphic=image.getGraphics();
       Panel panel=new Panel();
       JButton white=new JButton();
       JButton black=new JButton();
       JButton yellow=new JButton();
       JButton blue=new JButton();
       JButton red=new JButton();
       JButton green=new JButton();
       JButton orange=new JButton();
       JButton pink=new JButton();
       JButton magenta=new JButton();
       JButton undo=new JButton("undo");
       JPanel selectedColor=new JPanel();
       JLabel startXst=new JLabel("0");
       JLabel startYst=new JLabel("0");
       JLabel middleXst=new JLabel("0");
       JLabel middleYst=new JLabel("0");
       JLabel endXst=new JLabel("0");
       JLabel endYst=new JLabel("0");
       Color background=new Color(224,126,0);
       Container content=this.getContentPane();
       public void adding(){
              content.setLayout(null);
              content.setBackground(background);
              selectedColor.setBackground(Color.BLACK);
              white.setBackground(Color.WHITE);
              black.setBackground(Color.BLACK);
              yellow.setBackground(Color.YELLOW);
              blue.setBackground(Color.BLUE);
              red.setBackground(Color.RED);
              green.setBackground(Color.GREEN);
              orange.setBackground(Color.ORANGE);
              pink.setBackground(Color.PINK);
              magenta.setBackground(Color.MAGENTA);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(600,600);
              this.setLocation(150,90);
              undo.setBounds(190,128,100,34);
              white.setBounds(5,170,30,30);
              black.setBounds(37,170,30,30);
              yellow.setBounds(69,170,30,30);
              blue.setBounds(5,202,30,30);
              red.setBounds(37,202,30,30);
              green.setBounds(69,202,30,30);
              orange.setBounds(5,234,30,30);
              pink.setBounds(37,234,30,30);
              magenta.setBounds(69,234,30,30);
              selectedColor.setBounds(40,380,60,30);
              panel.setBounds(190,164,400,400);
              panel.requestFocus();
              startXst.setBounds(85,440,60,20);
              startYst.setBounds(85,460,60,20);
              middleXst.setBounds(85,480,60,20);
              middleYst.setBounds(85,500,60,20);
              endXst.setBounds(85,520,60,20);
              endYst.setBounds(85,540,60,20);
              content.add(white);
              content.add(black);
              content.add(yellow);
              content.add(blue);
              content.add(red);
              content.add(green);
              content.add(orange);
              content.add(pink);
              content.add(magenta);
              content.add(startXst);
              content.add(startYst);
              content.add(middleXst);
              content.add(middleYst);
              content.add(endXst);
              content.add(endYst);
              content.add(panel);
              content.add(selectedColor);
              content.add(undo);
              undo.addActionListener(this);
              white.addActionListener(this);
              black.addActionListener(this);
              yellow.addActionListener(this);
              blue.addActionListener(this);
              red.addActionListener(this);
              green.addActionListener(this);
              orange.addActionListener(this);
              pink.addActionListener(this);
              magenta.addActionListener(this);
              this.setVisible(true);
       public PainterDemo(){
              adding();
       public static void main(String[]args){
              new PainterDemo();
       public void actionPerformed(ActionEvent e) {
              Object button=e.getSource();
                     if(button==undo){//HERE I CALL MY IMAGE FROM STACK AND I SORT OF REPAINT IT...BUT IT DOES NOT WORK
                            BufferedImage temp=(BufferedImage)stack.pop();
                            panel.paint(temp.getGraphics());
                            panel.repaint();
       else if(button==white){
              selectedColor.setBackground(Color.WHITE);
       else if(button==black){
              selectedColor.setBackground(Color.BLACK);
       else if(button==yellow){
              selectedColor.setBackground(Color.YELLOW);
       else if(button==blue){
              selectedColor.setBackground(Color.BLUE);
       else if(button==red){
              selectedColor.setBackground(Color.RED);
       else if(button==green){
              selectedColor.setBackground(Color.GREEN);
       else if(button==orange){
              selectedColor.setBackground(Color.ORANGE);
       else if(button==pink){
              selectedColor.setBackground(Color.PINK);
       else if(button==magenta){
              selectedColor.setBackground(Color.MAGENTA);
       class Panel extends JPanel implements MouseListener,MouseMotionListener{
              public Panel(){
              this.addMouseListener(this);
              this.addMouseMotionListener(this);
       public void mouseClicked(MouseEvent e) {
       public void mousePressed(MouseEvent e) {
              int startX=e.getX();
              int startY=e.getY();
              startXst.setText(Integer.toString(startX));
              startYst.setText(Integer.toString(startY));
       public void mouseReleased(MouseEvent e) {
              int endX=e.getX();
              int endY=e.getY();
              endXst.setText(Integer.toString(endX));
              endYst.setText(Integer.toString(endY));
       stack.push(image);//HERE I PUSH MY IMAGE ON STACK OR AT LEAST I THINK SO
       public void mouseEntered(MouseEvent e) {
       public void mouseExited(MouseEvent e) {
       public void mouseDragged(MouseEvent e) {
              int xStart=Integer.parseInt(startXst.getText());
              int yStart=Integer.parseInt(startYst.getText());
              int x=e.getX();
              middleXst.setText(Integer.toString(x));
              int y=e.getY();
              middleYst.setText(Integer.toString(y));
              graphic=image.getGraphics();
              graphic.setColor(selectedColor.getBackground());
              graphic.drawLine(xStart,yStart,x,y);
       startXst.setText(Integer.toString(x));
       startYst.setText(Integer.toString(y));
       repaint();
       public void mouseMoved(MouseEvent e) {
       public void paint(Graphics g){
       super.paint(g);
       if(image!=null){
       g.drawImage(image,0,0,this);
}//this was missing for me

Similar Messages

  • Copy and paste image from IE to Illustrator

    Dear Illustrator users,
    I need to copy and paste images from IE10 or IE11 (Internet Explorer) to Illustrator (CS6, CC).
    I right-click image, choose "copy" in Internet Explorer
    now I can paste it to mspaint, word, photoshop, etc. It works fine..
    but when I try to paste image to Illustrator, it pastes url link instead of image.
    I know this problem comes with IE10. When I downgrade to IE9, it start to work fine.
    Any suggestion?
    Kind Regards,
    Jarda

    Hi Jacob,
    Thank you for a quick answer. Your suggestion is correct, but saving image to a file is an additional step.
    Since I do this task "thousands a day", this is unacceptable
    Any other suggestion?
    Regards,
    Jarda

  • I used to be able to copy and paste images from the internet into keynote slides and pages. Now when I copy and paste all I get is an empty  box. My iskysoft iTube studio has also stopped downloading videos. Is there an extension I need to enable?

    I used to be able to copy and paste images from the internet into keynote slides and pages. Now when I copy and paste all I get is an empty  box. My iskysoft iTube studio has also stopped downloading videos. Is there an extension I need to enable? Any ideas

    Try dragging the image to the desktop, then drag the image to the slide you want it on

  • Cut and Paste images from flash to power point

    Can you cut and paste images from flash player to power point?
    Thanks!

    Are the settings for the two Sequences completely indentical?
    -DH

  • How do i store and fetch image from the Database(Access)

    i am facing one problem in inserting the image into the database.the steps i followed as
    1)i have created one database(access) as "Image" and into that one table as "Image" and field as "image"
    type of the field is ole object.
    2)i have inserted one image into the image field through "database.vi"
    3)now i am trying to get the image from the database by "Fetching Example.vi"
    4)it will succesfully retrieve the image from that field .
    5)but when i close the both programs and reopen those that time i am unable to get retrieve the image.
    Attachments:
    Add_to_Database.vi ‏78 KB
    Fetch_from_database.vi ‏67 KB

    I would like to suggest different approach for saving the images in the database.
    I was working on Medical Imaging Company. The way we save the images in real-time was by writing the name and path of the images to database.
    The images themselves where saved directly to disk.
    I don�t think that access is very good in taking care of GBytes of data.
    It happens some time that the database gets damage. If you have the images separately you can create fix procedure. (We had one).
    Good Lack,
    Amit Shachaf,

  • Losing Metadata when extracting image from stack

    Hi,
    I have a series of 70 images that I edited in colour and B/W. They were stacked with the original RAW file in stacks of 3. I decided to extract the B/W versions to collect them in a separate folder. Now I discovered that from most B/W images the IPTC data is gone (and I had extensive captions and keyword lists). Only the info I filled in when importing the files from the camera remains. The IPTC of the other images in the stacks (RAW and a colour TIFFs) are in some cases gone too. So in more than 50% of the cases I have lost all added data in all three images from each stack.
    Has anyone had similar problems? Is there any way to recover the data of the images where all data is gone?
    In some stacks at least one of the images still has the data. So I can copy that again.
    Thanks,
    Ronald

    I don't have a file to test with mdls but I usually use ExifTool for metadata work.  Here is a script I wrote a while ago that will display all of the metadata contained in the file.
    https://www.johneday.com/219/exiftool-service-for-quick-metadata-access

  • Saving and loading images (png) on the iPhone / iPad locally

    Hi,
    you might find this helpful..
    Just tested how to save and load images, png in this case, locally on the i-Devices.
    In addition with a SharedObject it could be used as an image cache.
    Make sure you have the adobe.images.PNG encoder
    https://github.com/mikechambers/as3corelib/blob/master/src/com/adobe/images/PNGEncoder.as
    Not really tested, no error handling, just as a start.
    Let me know, what you think...
    Aaaaah and if somebody has any clue about this:
    http://forums.adobe.com/thread/793584?tstart=0
    would be great
    Cheers Peter
        import flash.display.Bitmap
         import flash.display.BitmapData
        import flash.display.Loader   
        import flash.display.LoaderInfo
        import flash.events.*
        import flash.filesystem.File
        import flash.filesystem.FileMode
        import flash.filesystem.FileStream
        import flash.utils.ByteArray;
        import com.adobe.images.PNGEncoder;
    private function savePic(){
        var bmp =  // Your Bitmap to save
        savePicToFile(bmp, "test.png")
    private function loadPic(){
         readPicFromFile("test.png")
    private function savePicToFile(bmp:Bitmap, fname:String){
           var ba:ByteArray = PNGEncoder.encode(bmp.bitmapData);
            var imagefile:File = File.applicationStorageDirectory;
            imagefile = imagefile.resolvePath(fname);
            var fileStream = new FileStream();
            fileStream.open(imagefile, FileMode.WRITE);
            fileStream.writeBytes(ba);
             trace("saved imagefile:"+imagefile.url)
    private function readPicFromFile(fname:String){
            var imagefile:File = File.applicationStorageDirectory;
            imagefile = imagefile.resolvePath(fname);
            trace("read imagefile:"+imagefile.url)
            var ba:ByteArray = new ByteArray();
            var fileStream = new FileStream();
            fileStream.open(imagefile, FileMode.READ);
            fileStream.readBytes(ba);
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPicRead)
            loader.loadBytes(ba);   
    private function onPicRead(e:Event){
        trace("onPicRead")
         var bmp:Bitmap = Bitmap(e.target.content)
         // Do something with it

    Are the movies transferred to your iPhone via the iTunes sync/transfer process but don't play on your iPhone?
    Copied from this link.
    http://www.apple.com/iphone/specs.html
    Video formats supported: H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30 frames per second, Low-Complexity version of the H.264 Baseline Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; H.264 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Baseline Profile up to Level 3.0 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats.
    What are you using for the conversion? Does whatever you are using for the conversion include an iPod or iPhone compatible setting for the conversion?
    iTunes includes a create iPod or iPhone version for a video in your iTunes library. Select the video and at the menu bar, go to Advanced and select Create iPod or iPhone version. This will duplicate the video in your iTunes library. Select this version for transfer to your iPhone to see if this makes any difference.

  • Does iPhone Packager CS 5.5 support camera access and LOADING images from the camera roll?

    Flash CS 5 only supports SAVING to the camera roll, not loading image from it. And it has no access to the camera to take pictures and access the image within the app.
    Does Flash CS 5.5 do these things? There's no point in upgrading if it doesn't support these core feature that I need.

    Hi.
    Just got an app  rejected because the popover to select the pics from the camera roll on  the iPad always appears on to-left corner, and the arrow doesn't point  anywere, and should be pointing to the button which activated it. That  "does not comply with the Apple iOS Human Interface Guidelines, as  required...". On the iPhone there's no issue because it takes over the  whole screen. More from the apple rejection message:
    "Specifically,  we noticed your app contained popover elements that didn't  point to  the element that revealed them. To avoid user confusion, a  popover  element's arrow should point to the element that revealed it."
    So, thanks for including the CameraRoll functionality, but it will be useless in the iPad apparently
    Any workaround to make it appear at a specific place when calling myCameraRoll.browseForImage() ?
    Fernando

  • Can i use labview to capture and process images from ip cameras connected to a switch.

    Hi,
    i have more then one ip cameras conneted in LAN by a switch. i have a PC conneted to same switch. is it possible to capture images from these ip cameras and process them(for example performing simple barcode scan or QR-code scan or OCR)?  Which IP cameras will be supported?

    There is functionally no difference whether the camera is connected directly to the system or via a switch. Both should work the same. The only real requirement that you'd need to care about is whether the switch can pass multicast UDP traffic correctly (this is used for network discovery of IP cameras). Generally all unmanaged switches (probably what you are using) will treat multicast traffic identical to broadcast traffic, but some managed switches/routers may need to be configured to pass multicast.
    Eric

  • 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?

  • Best practice for saving and recalling objects from disk?

    I've been using the OOP features of LabVIEW for various projects lately and one thing that I struggle with is a clean method to save and recall objects.
    Most of my design schemes have consisted of a commanding objects which holds a collection of worker objects.  Its a pretty simple model, but seems to work for some design problems.  The commander and my interface talk to each other and the commander sends orders to his minions in order to get things done.  For example, one parrent class might be called "Data Device Collection" and it has a property that is an array of "Data Device" objects.
    The Data Device object is a parent class and its children consist of various data devices such as "DAQmx Device", "O-Scope Device", "RS-232 Device", etc.
    When it comes to saving and loading data, the commanding class's "Save" or "Load" routine is called and at that time all of the minions' settings are saved or recalled from disk.
    My save routine is more-or-less straight forward, although it still requires an overwriting "Save" and "Load" vi.  Here is an example:
    It isn't too bad in that it is pretty straight forward and simple and there also would be no changes to this if the data structure of the class changed at all.  It also can save more generalized settings from it's parrent's class which is also a good feature.  What I don't like is that it looks essentially the same for each child class, but I'm at a loss on an effective way to move the handling of the save routing into the parent class.
    The load routine is more problematic for me.  Here is an example:
    Again, the desirability of moving this into the parent class would be awesome.  But the biggest complaint here is that I can't maintain my dynamic dispatch input-output requirements because the object that I load is strictly typed.  Instead I have to rely on reading the information from the loaded object and then writing that information to the object that exists on the dynamic dispatch wire.  I also dislike that unlike my Save Routine, I will need to modify this VI if my data structure of my object changes.
    Anyway, any input and insight would be great.  I'm really tired of writing these same VIs over-and-over-and-over again, and am after a better way to take care of this in the parent class by keeping the code generalized but still maintain the ability to bring back the saved parameters of each of the children classes.
    Thanks for your time.

    I'm with Ben. Don't rely on the current ability to serialize an object. Create a save method and implement some form of data persistence there. If you modify your class you might be disappointed when you cannot load objects you previously saved. It mostly works but as soon as you reset the version information in the class, you can no longer load the old objects. This is fine if you know how to avoid resetting the history. One thing that will do this is if you move the class into or out of a library. It becomes a new class with version 1.0.0 and it no longer recognizes the old objects.
    [Edit:  I see that you are just writing to a binary file. I'm not sure you can load older objects anyway using that method but I have never tried it.]
    This will not help you right now but there are plans for a nice robust API for saving objects.
    =====================
    LabVIEW 2012

  • How to load and retrieve images from Portal. URGENT

    Dear all,
    I've designed a table with an ordsys.ordimage field for images. BIG MISTAKE, because there is no possibility to upload images from a form. I'd like to change it into a BLOB field but an error arises:
    "You cannot modify the column definition for types CLOB, NCLOB, BFILE, BLOBand Intermedia Object types(ORDSYS.ORDIMAGE, ORDSYS.ORDAUDIO, ORDSYS.ORDVIDEO). (WWV-17079)"
    Could I change it anyhow in order not to build a new table? I have a lot of forms referring to that table and I should change these forms too....(and we know it is pretty difficult)...
    I would appreciate any help.
    Tomas

    Tomas,
    Do you have any active constraints on that specific row? If the row is accessed by other forms (tables etc) you would need to disable them (for example foreign key constraints) and update the row (or remove and re-add it).
    Kostas

  • How to load and retrieve images from Portal!!!

    Dear all,
    I've designed a table with an ordsys.ordimage field for images. BIG MISTAKE, because there is no possibility to upload images from a form. I'd like to change it into a BLOB field but an error arises:
    "You cannot modify the column definition for types CLOB, NCLOB, BFILE, BLOBand Intermedia Object types(ORDSYS.ORDIMAGE, ORDSYS.ORDAUDIO, ORDSYS.ORDVIDEO). (WWV-17079)"
    Could I change it anyhow in order not to build a new table? I have a lot of forms referring to that table and I should change these forms too....(and we know it is pretty difficult)...
    I would appreciate any help.
    Tomas

    Tomas,
    Do you have any active constraints on that specific row? If the row is accessed by other forms (tables etc) you would need to disable them (for example foreign key constraints) and update the row (or remove and re-add it).
    Kostas

  • Copy and paste image from PDF to another application

    how do you copy and paste an image from PDF into another application such as Word or Excel? I know how to copy>> hover cursor over picture until it turns into a select "+" tool, select and right click to copy but when I try to paste it into another application, its loses all of its formatting. Thanks

    Not sure what you mean by formatting of a picture. You can export all images and get a files to import to word. You can also use the snapshot tool, though it captures a screen copy. If you select an image and copy, my experience has been that it will only copy to PhotoShop, but it is not something I do very much. If the image is part of the document (not markup like a stamp or such), you can use the select tool to select the image and copy it to the clipboard. Just tried it and it worked fine. If it is a stamp (like pasted in), then you can not copy it in this way, if at all.

  • How to copy and paste images from Internet to keynote on iPad?

    I want to make presentations on the go using Internet images and keynote. How can I get images from websites copied into my photo album, as that seems to be the only way you can add a image in keynote. Is there legal problems involved in it? Because I can do it no problem using my desktop etc.
    Thanks,
    Dave

    Click and drag is your friend!
    This thread probably belongs in the safari area, but anyway:
    If you click and hold, there should be a cursor that appears with a file. Then, simply drag it to your desktop where the file will appear.
    Or:
    Right-click (control-click) the picture and there should be a 'save image' or 'save image as' option. Select that, then save it!
    Afterwards, simply find the file in your screen saver options in system preferences, and then select it.
    Good Luck!

Maybe you are looking for

  • Can not find the the RBS tables after installing the Remote Blog Storage

    Hi, I am trying to configure the Remote Blob storage on my Sharepoint Server 2013. I am using the SQL Server Express 10.50.6000. Everything is going fine, but I can not find the tables in the Database. I am not sure where I did the wrong thing. machi

  • How do i create a workflow to delete tasks.

    I've created a workflow that will take the Title, Start Date, and End Date from one list (roomReserved) and then create a task on another list (centralCal) setup as a central calendar. When a yes/no checkbox is checked, it will then create the task o

  • Mapping help required - extension

    Hi, I 've done the mapping based on the below conditions Let say 3 fields called : a,b,c if a = RAM then b = b/c here b field is in one segment and a & c fields are in child segment of above segment. Note : all the above fields occurance : 0 to 1 But

  • How to get iDVD on new Mac.

    Just bought a new Macbook air 11" running on Os X 10.7.2 and a superdrive so i could burn DVD's.... but no iDVD! I have it now and it works perfectly....after a little research. This is where i started, very helpful: http://www.youtube.com/watch?v=my

  • Slide Show Corruption

    I'm building my first iPhoto 09 slideshow, using the Sliding Panels theme. I've worked with previous versions of iPhoto, and am impressed with this theme, except ... In one particular spot in the the slideshow, I can't adjust the picture -- it always