Write to bufferedimage and compatibleimages

hey
you maybe remember that I made a breakout game, i use compatibleimages in fullscreen and draw them alot of times..300+
someone told me to use a bufferedImage and draw the image to this bufferedImage first then just blit the bufferedImage.
is this correct?will that result in 1 blit instead of 300? and is if faster? the game has 70 fps now.

hmm, the answer can be either yes or no.
edit ESSAY ALERT :D
if hardware acceleration is supported, your current way of doing it will be quicker.
If hardware acceleration is not supported, reducing the number of blits may well increase speed.
heres an outline of what the processes involve :-
When hardware acceleration is supported
A) Blitting each block seperately
1) the framebuffer (back & front buffers) are both stored in vram.
2) each blocks image is stored in main memory, and cached in vram.
3) any blit operations are vram->vram, hence have near zero execution cost.
B) Blitting each block to an intermediary image (when a change occurs), then blitting this intermediary image to the frame buffer.
1) the frame buffer (back & front buffers) are both stored in vram.
2) each blocks image is stored in main memory, and cached in vram. (though the vram cached version will never be used)
3) the intermediary image is stored in main memory, and cached in vram.
4) the regular blit operation will be
intermediary image->frame buffer
since both of these are in vram, the cost is near zero.
5) when the intermediary image changes, the blit operation is
blocks image->intermediary image
since both these images have their original image stored in main memory,
this blit is a main mem.->main mem. hence, will incur a speed cost.
6) ALSO, when the intermediary image changes, the version cached in vram
becomes invalid, and the image needs to be re-cached.
This is a main mem.->vram copy, which also incurs a cost.
If the intermediary image changes often, this will result in a drop in framerate each time a change occurs.
(inconsistant framerates are VERY bad from a human perception POV)
C) use a VolatileImage object for the intermediary image
This is the best solution, as it removes all main mem->vram blits, and also reduces the vram->vram blits to an absolute minimum.
However,
the real speed difference between 300 vram blits
and 1vram blit(+1 vram blit each time a change occurs)
is absolutely minimal.
(infact, because this isnt your bottleneck the speed difference will be zero)
When hardware acceleration is NOT supported
A) Blitting each block seperately
1) the back buffer is in main mem. the front buffer is in vram.
2) each blocks image is stored in main memory.
3) each block blit is main mem.->main mem. (costly)
PLUS the back buffer has to be blitted onto the front buffer, this is a main mem.->vram blit.
B) Blitting each block to an intermediary image (when a change occurs), then blitting this intermediary image to the frame buffer.
1) the back buffer is in main mem. the front buffer is in vram.
2) each blocks image is stored in main memory.
3) the intermediary image is stored in main mem.
4) the regular blit operation will be
intermediary image->back buffer
this is a single main mem.->main mem. blit.
5) also, each time the intermediary image changes,
you will get an extra main mem->main mem blit.
6) you also have the obligatory back buffer->front buffer blit
Comparing the 2 methods when there is no hardware acceleration available
you will see that the 2nd technique does indeed require fewer blits.
(instead of 300 every frame, your doing 1+[1 each time a change occurs])
So, now your left with the question, 'which do I use?'
well, its totally down to whether you expect hardware acceleration to be available or not :S
The ideal solution is to write 2 versions,
not very 'Java', but its the way the world is :[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Memory Efficiency of BufferedImage and ImageIO

    This thread discusses the memory efficiency of BufferedImage and ImageIO. I also like to know whether if there's possible memory leak in BufferedImage / ImageIO, or just that the result matches the specifications. Any comments are welcomed.
    My project uses a servlet to create appropriate image tiles (in PNG format) that fits the specification of google map, from images stored in a database. But it only takes a few images to make the system out of heap memory. Increasing the initial heap memory just delays the problem. So it is not acceptable.
    To understand why that happens, I write a simple code to check the memory usage of BufferedImage and ImageIO. The code simply keeps making byte arrays from the same image until it is running out of the heap memory.
    Below shows how many byte arrays it can create:
    1M jpeg picture (2560*1920):
    jpeg = 123
    png = 3
    318K png picture (1000*900):
    jpeg = 1420
    png = 178
    Notice that the program runs out of memory with only 3 PNG byte arrays for the first picture!!!! Is this normal???
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    import javax.imageio.*;
    import java.io.*;
    import javax.swing.*;
    import java.util.*;
    public class Test {
         public static void main(String[] args) {
              Collection images = new ArrayList();
              for (;;) {
                   try {
                        BufferedImage img = ImageIO.read(new File("PTHNWIDE.png"));
                        img.flush();
                        ByteArrayOutputStream out =
                             new ByteArrayOutputStream();
                        ImageIO.write(img, "png", out); // change to "jpeg" for jpeg
                        images.add(out.toByteArray());
                        out.close();
                   } catch (OutOfMemoryError ome) {
                        System.err.println(images.size());
                        throw ome;
                   } catch (Exception exc) {
                        exc.printStackTrace();
                        System.err.println(images.size());
    }

    a_silent_lamb wrote:
    1. For the testing program, I just use the default VM setting, ie. 64M memory so it can run out faster. For server, the memory would be at least 256M.You might want to increase the heap size.
    2. Do you mean it's 2560*1920*24bits when loaded? Of course.
    That's pretty (too) large for my server usage, Well you have lots of image data
    because it will need to process large dimension pictures (splitting each into set of 256*256 images). Anyway to be more efficient?Sure, use less colors :)

  • BufferedImages and Swing's ScrollablePicture in a JPanel

    I'm referring to http://java.sun.com/developer/technicalArticles/Media/imagestrategies/index.html paper.
    As I read this excellent paper, I decided to go for the BufferedImage strategy.
    But I can't put my BufferedImage into my ScrollablePicture as below:
    JPanel picPanel = new JPanel(new GridBagLayout());
    //Set up the scroll pane.
    picture = new ScrollablePicture(imageIcon_, columnView.getIncrement()); // OK
    //picture = new ScrollablePicture(bImg, columnView.getIncrement()); // NOT OK = don't work
    ...How to bypass the message "java:542: cannot resolve symbol symbol : constructor ScrollablePicture (java.awt.image.BufferedImage,int)"
    It is very important as all my code is based on BufferedImage to apply many operations on the image.
    ? I believe the API does not allow to perform RGB to B&W operation on ImageIcon. ?
    Thanks to all.
    dimitryous r.

    Hi camickr,
    Hi all,
    I pass trough my SSCCE. Good advice from camickr. But it was not so easy:
    Short: not so short
    Self contained: believe so
    Correct: Java 1.4.2 code
    Compilable: yes
    I'm back with formatted code.
    I'm sure you will fire at me all of you. Anyway if I don't even try, I will never succeed.
    //  TooAwoo.java
    //  TooAwoo
    //     part of this code is from Sun's JavaTutorial 1.4.2
    import java.applet.Applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.GraphicsEnvironment;
    import java.awt.image.*;
    import java.lang.*;
    import java.lang.String;
    import java.lang.Object;
    import java.net.URL;
    import java.net.MalformedURLException;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.event.MouseInputAdapter;
    import javax.swing.ImageIcon;
    import javax.swing.JScrollPane;
    import javax.swing.JToggleButton;
    import java.io.FilePermission;
    public class TooAwoo extends JApplet implements
                                                                ChangeListener,
                                                                ActionListener,
                                                                ItemListener
         FilePermission p = new FilePermission("<<ALL FILES>>", "read,write");
        public BufferedImage bImg;
         Font newFont = new Font("SansSerif", Font.PLAIN, 10);
         ImageControls RightPanel;
         public static int initOx = 0;
         public static int initOy = 0;
         int init_ww, init_wh, set_x, set_y = 0;
         final int pSP_w = 520; // final width of pictureScrollPane
         final int pSP_h = 650; // final height of pictureScrollPane
         Dimension applet_window; // applet dimensions
         public Image image;
         public ImageIcon imageIcon_;
         public static BufferedImage binull;
         // ScrollablePicture stuff
         public Rule columnView;
        public Rule rowView;
         public JToggleButton isMetric;
        public ScrollablePicture picture;
         public JScrollPane pictureScrollPane;
         public TooAwoo() {
              // nothing here
        public void init() {
              applet_window = getSize();                                                            // read applet dimensions in TooAwoo.html
              init_ww = applet_window.width;
              init_wh = applet_window.height;
              // get the image to use width > 680 (see final int pSP_w above)
              image = getImage(getDocumentBase(), "images/ReallyBig.jpg");
              imageIcon_ = createImageIcon("images/ReallyBig.jpg");
              int iw = imageIcon_.getIconWidth();
              int ih = imageIcon_.getIconHeight();
              bImg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
              // Panels
              // ImageDisplayPanel
            //Create the row and column headers.
            columnView = new Rule(Rule.HORIZONTAL, true);
            rowView = new Rule(Rule.VERTICAL, true);
            if (imageIcon_ != null) {
                columnView.setPreferredWidth(imageIcon_.getIconWidth());
                rowView.setPreferredHeight(imageIcon_.getIconHeight());
            } else {
                columnView.setPreferredWidth(640);
                rowView.setPreferredHeight(480);
            //Create the upper left corner.
            JPanel buttonCorner = new JPanel();                                                  //use FlowLayout
            isMetric = new JToggleButton("cm", true);
            isMetric.setFont(newFont);
            isMetric.setMargin(new Insets(2,2,2,2));
            isMetric.addItemListener(this);                                                       // !!! not OK = don't work: button is not firing
            buttonCorner.add(isMetric);
              JPanel ImageDisplayPanel = new JPanel(new GridBagLayout());
            //Set up the scroll pane.
              picture = new ScrollablePicture(imageIcon_, columnView.getIncrement());     // either
              //picture = new ScrollablePicture(bImp, columnView.getIncrement());          // or
              // ********** if bImp change the lines in ScrollablePicture.java **********
            Graphics g = bImg.getGraphics();
              g.drawImage(bImg, 0, 0, null);
              JScrollPane pictureScrollPane = new JScrollPane(picture);
            pictureScrollPane.setPreferredSize(new Dimension(pSP_w, pSP_h));
            pictureScrollPane.setViewportBorder(
                    BorderFactory.createLineBorder(Color.black));
            pictureScrollPane.setColumnHeaderView(columnView);
            pictureScrollPane.setRowHeaderView(rowView);
              //Set the corners.
            pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner);
            pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER,
                                        new Corner());
            pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER,
                                        new Corner());
              //set_y++;
              addToGridBag(ImageDisplayPanel,pictureScrollPane, set_x, set_y, 1, 1, 0, 0); // 0,0
              getContentPane().add( BorderLayout.WEST, ImageDisplayPanel);               // where to display the bImg: left
              RightPanel = new ImageControls();                                                  // call the ImageControls class
              RightPanel.setBackground(Color.black);
              getContentPane().add( BorderLayout.EAST, RightPanel);
              //getContentPane().add( BorderLayout.EAST, ToolsPanel);                         // where to display the tools: right
              JPanel GlobalPanel = new JPanel(new GridBagLayout());
              getContentPane().add( BorderLayout.NORTH, GlobalPanel);
         } // end public void init()
         public Graphics2D createGraphics2D(int width,
                                                    int height,
                                                    BufferedImage bi,
                                                    Graphics g) {                                   // called by ImageControls paint
              Graphics2D g2 = null;
              if (bi != null) {
                   System.out.println("TooAwoo createGraphics2D: bi != null : " + " w= " + width + " h= " + height);
                   g2 = bi.createGraphics();
              } else {
                   System.out.println("TooAwoo createGraphics2D: bi == null g2 = (Graphics2D) g");
                   g2 = (Graphics2D) g;
              return g2; // return to ImageControls paint
         } // end createGraphics2D
         class ImageControls extends JPanel {
              public void paint(Graphics g) {
                   Dimension applet_window = getSize();
                   if (bImg == null) {
                        bImg = createBufferedImage(applet_window.width, applet_window.height, 2);
                   } else {
                        Graphics2D g2 = createGraphics2D(applet_window.width, applet_window.height, bImg, g);
                        g.drawImage( bImg , initOx , initOy , null );
                        g2.dispose();
                        //toolkit.sync();
                   } // end else (bImg != null)
              } // end paint
         } // end ImageControls
         public Dimension setPreferredSize() {
              Dimension applet_window = getSize();
              return applet_window;
         public String getString(String key) {
              return key;
         public BufferedImage createBufferedImage(int w, int h, int imgType) {          // called by ImageControls paint
              BufferedImage bi = null;
              if (imgType == 0) {
                   bi = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(w, h);
              } else if (imgType > 0 && imgType < 14) {
                   bi = new BufferedImage(w, h, imgType);
              System.out.println("TooAwoo createBufferedImage: imgType= " + imgType + " w= " + w + " h= " + h);
              return bi;
         public static void addToGridBag(JPanel panel, Component comp,
                                                 int x, int y, int w, int h, double weightx, double weighty) {
              GridBagLayout gbl = (GridBagLayout) panel.getLayout();
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
              c.anchor = GridBagConstraints.WEST;
              c.gridx = x;
              c.gridy = y;
              c.gridwidth = w;
              c.gridheight = h;
              c.weightx = weightx;
              c.weighty = weighty;
              panel.add(comp);
              gbl.setConstraints(comp, c);
         } // end addToGridBag
         protected static ImageIcon createImageIcon(String path) {                         // Returns an ImageIcon, or null if the path was invalid.
              java.net.URL imgURL = TooAwoo.class.getResource(path);
              if (imgURL != null) {
                   return new ImageIcon(imgURL);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
         } // end createImageIcon
         private static void createAndShowGUI() {                                             // called by main
              JFrame frame = new JFrame("TooAwoo");                                             //Create and set up the window.
              // Make sure we have nice window decorations.
              frame.setDefaultLookAndFeelDecorated(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up content pane.
              frame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              JPanel masterPanel = new JPanel();
              frame.add("Center", masterPanel);
              // Display the window.
              frame.pack();
              frame.setSize(new Dimension( 1000 , 640 ));
              frame.setVisible(true);
         } // end createAndShowGUI
         public static void main(String s[]) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
         } // end main
         public void actionPerformed(ActionEvent e) {
              repaint(1024);
        public void stateChanged(ChangeEvent e) {
              repaint(1024);
         public void itemStateChanged(ItemEvent e) {
              Object obj = e.getSource();
              if ( obj == isMetric ) {
                   System.out.println("obj isMetric");
                //Turn it to metric.
                rowView.setIsMetric(true);
                columnView.setIsMetric(true);
                   picture.setMaxUnitIncrement(rowView.getIncrement());
            } else {
                System.out.println("obj isNotMetric");
                   //Turn it to inches.
                rowView.setIsMetric(false);
                columnView.setIsMetric(false);
                   picture.setMaxUnitIncrement(rowView.getIncrement());
         } // end itemStateChanged(ItemEvent e)
    } // end TooAwoo
    Next is ScrollablePicture.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class ScrollablePicture extends JLabel implements Scrollable {
        private int maxUnitIncrement = 1;
         private boolean missingPicture = false;
        public ScrollablePicture (ImageIcon imageIcon_, int m){                              //(BufferedImage bImg, int m)
            super(imageIcon_); // comment this line if bImg...
              if (imageIcon_ == null) { // change imageIcon_ to bImg if bImg...
                   missingPicture = true;
                   setText("No picture found.");
                   setHorizontalAlignment(CENTER);
                   setOpaque(true);
                   setBackground(Color.black);
              maxUnitIncrement = m;
        public Dimension getPreferredScrollableViewportSize() {
            return getPreferredSize();
        public int getScrollableUnitIncrement(Rectangle visibleRect,
                                              int orientation,
                                              int direction) {
            //Get the current position.
            int currentPosition = 0;
            if (orientation == SwingConstants.HORIZONTAL)
                currentPosition = visibleRect.x;
            else
                currentPosition = visibleRect.y;
            //Return the number of pixels between currentPosition
            //and the nearest tick mark in the indicated direction.
            if (direction < 0) {
                int newPosition = currentPosition -
                   (currentPosition / maxUnitIncrement) *
                   maxUnitIncrement;
                return (newPosition == 0) ? maxUnitIncrement : newPosition;
            } else {
                return ((currentPosition / maxUnitIncrement) + 1) *
                   maxUnitIncrement - currentPosition;
        public int getScrollableBlockIncrement(Rectangle visibleRect,
                                               int orientation,
                                               int direction) {
            if (orientation == SwingConstants.HORIZONTAL)
                return visibleRect.width - maxUnitIncrement;
            else
                return visibleRect.height - maxUnitIncrement;
        public boolean getScrollableTracksViewportWidth() {
            return false;
        public boolean getScrollableTracksViewportHeight() {
            return false;
        public void setMaxUnitIncrement(int pixels) {
            maxUnitIncrement = pixels;
    Next is Corner.java
    import java.awt.*;
    import javax.swing.*;
    public class Corner extends JComponent {
        protected void paintComponent(Graphics g) {
            g.setColor(new Color(230, 163, 4));
            g.fillRect(0, 0, getWidth(), getHeight());
    Next is Rule.java
    import java.awt.*;
    import javax.swing.*;
    public class Rule extends JComponent {
        public static final int INCH = Toolkit.getDefaultToolkit().
                getScreenResolution();
        public static final int HORIZONTAL = 0;
        public static final int VERTICAL = 1;
        public static final int SIZE = 30;
        public int orientation;
        public boolean isMetric;
        private int increment;
        private int units;
        public Rule(int o, boolean m) {
            orientation = o;
            isMetric = m;
            setIncrementAndUnits();
        public void setIsMetric(boolean isMetric) {
            this.isMetric = isMetric;
            setIncrementAndUnits();
            repaint();
        private void setIncrementAndUnits() {
            if (isMetric) {
                units = (int)((double)INCH / (double)2.54); // dots per centimeter
                increment = units;
            } else {
                units = INCH;
                increment = units / 2;
        public boolean isMetric() {
            return this.isMetric;
        public int getIncrement() {
            return increment;
        public void setPreferredHeight(int ph) {
            setPreferredSize(new Dimension(SIZE, ph));
        public void setPreferredWidth(int pw) {
            setPreferredSize(new Dimension(pw, SIZE));
        protected void paintComponent(Graphics g) {
            Rectangle drawHere = g.getClipBounds();
            // Fill clipping area with dirty brown/orange.
            g.setColor(new Color(230, 163, 4));
            g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
            // Do the ruler labels in a small font that's black.
            g.setFont(new Font("SansSerif", Font.PLAIN, 10));
            g.setColor(Color.black);
            // Some vars we need.
            int end = 0;
            int start = 0;
            int tickLength = 0;
            String text = null;
            // Use clipping bounds to calculate first and last tick locations.
            if (orientation == HORIZONTAL) {
                start = (drawHere.x / increment) * increment;
                end = (((drawHere.x + drawHere.width) / increment) + 1)
                      * increment;
            } else {
                start = (drawHere.y / increment) * increment;
                end = (((drawHere.y + drawHere.height) / increment) + 1)
                      * increment;
            // Make a special case of 0 to display the number
            // within the rule and draw a units label.
            if (start == 0) {
                text = Integer.toString(0) + (isMetric ? " cm" : " in");
                tickLength = 8;//10;
                if (orientation == HORIZONTAL) {
                    g.drawLine(0, SIZE-1, 0, SIZE-tickLength-1);
                    g.drawString(text, 2, 21);
                } else {
                    g.drawLine(SIZE-1, 0, SIZE-tickLength-1, 0);
                    g.drawString(text, 9, 10);
                text = null;
                start = increment;
            // ticks and labels
            for (int i = start; i < end; i += increment) {
                if (i % units == 0)  {
                    tickLength = 7;//10;
                    text = Integer.toString(i/units);
                } else {
                    tickLength = 4;//7;
                    text = null;
                if (tickLength != 0) {
                    if (orientation == HORIZONTAL) {
                        g.drawLine(i, SIZE-1, i, SIZE-tickLength-1);
                        if (text != null)
                            g.drawString(text, i-3, 21);
                    } else {
                        g.drawLine(SIZE-1, i, SIZE-tickLength-1, i);
                        if (text != null)
                            g.drawString(text, 9, i+3);
    Here is TooAwoo.html
    <HTML>
    <HEAD>
    <TITLE>TooAwoo</TITLE>
    </HEAD>
    <BODY>
    <APPLET archive="TooAwoo.jar" code="TooAwoo" width=1024 height=800>
    Your browser does not support Java, so nothing is displayed.
    </APPLET>
    </BODY>
    </HTML>
    */Total number of lines: 486
    Weight: 15 199 bytes
    Total number of files: 5
    TooAwoo.java
    ScrollablePicture.java
    Corner.java
    Rule.java
    TooAwoo.html
    ... in that order in my code
    The major default is: I cannot have that BuffuredImage at the left of the screen if run using bImp at line 91 of TooAwoo.java.
    Minor bug: the JToggle button (inch/cm) does not fires-up correctly. Nothing change.
    Anyway feel free to fire at me if you believe its a good strategy. I will remain very positive to all comments and suggestions.
    Thanks.
    dimitryous r.

  • Need help: BufferedImage and zooming

    please help me understand what i am doing wrong. i am having a hard time understanding the concept behind BufferedImage and zooming. the applet code loads an image as its background. after loading, you can draw line segments on it. but when i try to zoom in, the image in the background remains the same in terms of size, line segments are the only ones that are being zoomed, and the mouse coordinates are confusing.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.imageio.*;
    import java.io.*;
    import java.util.ArrayList;
    import java.io.IOException;
    import java.net.URL;
    import java.awt.image.*;
    public class Testing extends JApplet {
         private String url;
         private Map map;
         public void init() {
         public void start()
              url = "http://localhost/image.gif";
                  map = new Map(url);
                 getContentPane().add(map, "Center");
                 validate();
                 map.validate();
    class Map extends JPanel implements MouseListener, MouseMotionListener{
         private Image image;
         private ArrayList<Point2D> points;
         private ArrayList<Line2D> lineSegment;
         private Point2D startingPoint;
         private int mouseX;
         private int mouseY;
         private BufferedImage bimg;
         private AffineTransform xform;
         private AffineTransform inverse;
         private double zoomFactor = 1;
         public Map(String url)
                         super();
              //this.image = image;
              try
                   image = ImageIO.read(new URL(url));
              catch(Exception e)
              Insets insets = getInsets();
              xform = AffineTransform.getTranslateInstance(insets.left, insets.top);
              xform.scale(zoomFactor,zoomFactor);
              try {
                   inverse = xform.createInverse();
              } catch (NoninvertibleTransformException e) {
                   System.out.println(e);
              points = new ArrayList();
              startingPoint = new Point();
              bimg = new BufferedImage(this.image.getWidth(this), this.image.getHeight(this), BufferedImage.TYPE_INT_ARGB);
              repaintBImg();
              addMouseListener(this);
              addMouseMotionListener(this);
         public void paintComponent(Graphics g)
            Graphics2D g2d = (Graphics2D)g;
              g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
              g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING , RenderingHints.VALUE_RENDER_QUALITY ));
            bimg = (BufferedImage)image;
            g2d.drawRenderedImage(bimg, xform);
            if(!points.isEmpty())
                 for(int i=0; i<points.size(); i++)
                      if(i > 0)
                           drawLineSegment(g2d,points.get(i-1),points.get(i));
                      drawPoint(g2d, points.get(i));
            if(startingPoint != null)
                drawTempLine(startingPoint, g2d);
            else
                mouseX = 0;
                mouseY = 0;
         private void repaintBImg()
              bimg.flush();
              Graphics2D g2d = bimg.createGraphics();
              g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
              g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING , RenderingHints.VALUE_RENDER_QUALITY ));
            g2d.drawRenderedImage(bimg, xform);
            g2d.dispose();
         private void drawPoint(Graphics2D g2d, Point2D p)
            int x = (int)(p.getX() * zoomFactor);
            int y = (int)(p.getY() * zoomFactor);
            int w = (int)(13 * zoomFactor);
            int h = (int)(13 * zoomFactor);
              g2d.setColor(Color.ORANGE);
              g2d.setStroke(new BasicStroke(1.0F));
            g2d.fillOval(x - w / 2, y - h / 2, w, h);
            g2d.setColor(Color.BLACK);
            g2d.drawOval(x - w / 2, y - h / 2, w - 1, h - 1);
         private void drawLineSegment(Graphics2D g2d, Point2D p1, Point2D p2)
              double x1 = p1.getX() * zoomFactor;
                 double y1 = p1.getY() * zoomFactor;
                 double x2 = p2.getX() * zoomFactor;
                 double y2 = p2.getY() * zoomFactor;
                 g2d.setColor(Color.RED);
                 g2d.setStroke(new BasicStroke(3.0F));
                 g2d.draw(new java.awt.geom.Line2D.Double(x1, y1, x2, y2));
             private void drawTempLine(Point2D p, Graphics2D g2d)
                 int startX = (int)(p.getX() * zoomFactor);
                 int startY = (int)(p.getY() * zoomFactor);
                 if(mouseX != 0 && mouseY != 0)
                         g2d.setColor(Color.RED);
                          g2d.setStroke(new BasicStroke(2.0F));
                          g2d.drawLine(startX, startY, mouseX, mouseY);
         public void mouseClicked(MouseEvent e)
         public void mouseDragged(MouseEvent e)
              mouseX = (int)(e.getX()*zoomFactor);
              mouseY = (int)(e.getY()*zoomFactor);
              repaint();
         public void mousePressed(MouseEvent e)
              if(e.getButton() == 1)
                   points.add(inverse.transform(e.getPoint(), null));
                   if(points.size() > 0)
                        startingPoint = points.get(points.size()-1);
                        mouseX = mouseY = 0;
                   repaint();
              else if(e.getButton() == 2)
                   zoomFactor = zoomFactor + .05;
                   repaintBImg();
              else if(e.getButton() == 3)
                   zoomFactor = zoomFactor - .05;
                   repaintBImg();
         public void mouseReleased(MouseEvent e)
              if(e.getButton() == 1)
                   points.add(inverse.transform(e.getPoint(), null));
              repaint();
         public void mouseEntered(MouseEvent mouseevent)
         public void mouseExited(MouseEvent mouseevent)
         public void mouseMoved(MouseEvent mouseevent)
    }Message was edited by:
    hardc0d3r

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.awt.geom.*;
    import java.io.*;
    import java.net.URL;
    import java.util.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class ZoomTesting extends JApplet {
        public void init() {
            //String dir = "file:/" + System.getProperty("user.dir");
            //System.out.printf("dir = %s%n", dir);
            String url = "http://localhost/image.gif";
                         //dir + "/images/cougar.jpg";
            MapPanel map = new MapPanel(url);
            getContentPane().add(map, "Center");
        public static void main(String[] args) {
            JApplet applet = new ZoomTesting();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(applet);
            f.setSize(400,400);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    class MapPanel extends JPanel implements MouseListener, MouseMotionListener {
        private BufferedImage image;
        private ArrayList<Point2D> points;
        private Point2D startingPoint;
        private int mouseX;
        private int mouseY;
        private AffineTransform xform;
        private AffineTransform inverse;
        RenderingHints hints;
        private double zoomFactor = 1;
        public MapPanel(String url) {
            super();
            try {
                image = ImageIO.read(new URL(url));
            } catch(Exception e) {
                System.out.println(e.getClass().getName() +
                                   " = " + e.getMessage());
            Map<RenderingHints.Key, Object> map =
                        new HashMap<RenderingHints.Key, Object>();
            map.put(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            map.put(RenderingHints.KEY_RENDERING,
                    RenderingHints.VALUE_RENDER_QUALITY);
            hints = new RenderingHints(map);
            setTransforms();
            points = new ArrayList<Point2D>();
            startingPoint = new Point();
            addMouseListener(this);
            addMouseMotionListener(this);
        private void setTransforms() {
            Insets insets = getInsets();
            xform = AffineTransform.getTranslateInstance(insets.left, insets.top);
            xform.scale(zoomFactor,zoomFactor);
            try {
                inverse = xform.createInverse();
            } catch (NoninvertibleTransformException e) {
                System.out.println(e);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHints(hints);
            g2d.drawRenderedImage(image, xform);
            if(!points.isEmpty()) {
                for(int i=0; i<points.size(); i++) {
                    if(i > 0)
                        drawLineSegment(g2d,points.get(i-1),points.get(i));
                    drawPoint(g2d, points.get(i));
            if(startingPoint != null) {
                drawTempLine(startingPoint, g2d);
            } else {
                mouseX = 0;
                mouseY = 0;
        private void drawPoint(Graphics2D g2d, Point2D p) {
            int x = (int)(p.getX() * zoomFactor);
            int y = (int)(p.getY() * zoomFactor);
            int w = (int)(13 * zoomFactor);
            int h = (int)(13 * zoomFactor);
            g2d.setColor(Color.ORANGE);
            g2d.setStroke(new BasicStroke(1.0F));
            g2d.fillOval(x - w / 2, y - h / 2, w, h);
            g2d.setColor(Color.BLACK);
            g2d.drawOval(x - w / 2, y - h / 2, w - 1, h - 1);
        private void drawLineSegment(Graphics2D g2d, Point2D p1, Point2D p2) {
            double x1 = p1.getX() * zoomFactor;
            double y1 = p1.getY() * zoomFactor;
            double x2 = p2.getX() * zoomFactor;
            double y2 = p2.getY() * zoomFactor;
            g2d.setColor(Color.RED);
            g2d.setStroke(new BasicStroke(3.0F));
            g2d.draw(new java.awt.geom.Line2D.Double(x1, y1, x2, y2));
        private void drawTempLine(Point2D p, Graphics2D g2d) {
            int startX = (int)(p.getX() * zoomFactor);
            int startY = (int)(p.getY() * zoomFactor);
            if(mouseX != 0 && mouseY != 0) {
                g2d.setColor(Color.RED);
                g2d.setStroke(new BasicStroke(2.0F));
                g2d.drawLine(startX, startY, mouseX, mouseY);
        public void mouseClicked(MouseEvent e) {}
        public void mouseDragged(MouseEvent e) {
            mouseX = (int)(e.getX()*zoomFactor);
            mouseY = (int)(e.getY()*zoomFactor);
            repaint();
        public void mousePressed(MouseEvent e) {
            if(e.getButton() == 1) {
                points.add(inverse.transform(e.getPoint(), null));
                if(points.size() > 0) {
                    startingPoint = points.get(points.size()-1);
                    mouseX = mouseY = 0;
            } else if(e.getButton() == 2) {
                zoomFactor = zoomFactor + .05;
                setTransforms();
            } else if(e.getButton() == 3) {
                zoomFactor = zoomFactor - .05;
                setTransforms();
            repaint();
        public void mouseReleased(MouseEvent e) {
            if(e.getButton() == 1) {
                points.add(inverse.transform(e.getPoint(), null));
            repaint();
        public void mouseEntered(MouseEvent mouseevent) {}
        public void mouseExited(MouseEvent mouseevent) {}
        public void mouseMoved(MouseEvent mouseevent) {}
    }

  • How can I write a file and fill it in periods?

    Hi Every body!
    I need help with this.
    I have my aplication(power quality analiser),This VI obtain several varibles and make a lot of calculus and operation, to obtein others parameters in real time so my problem is Save the acquire data and calculus data into a file (similar as a report) every period(custumizable for the user in time units) 
    I mean make a only one file wich is write every period continuously , e.g.  Start my principal VI and this event start the write of file, past one period,make other row or colum into the same file and continue that way until we stop the principal VI.
    How can I make that?
    Thaks very much 
    Best Regards

    Hi,
    assuming you have your trigger (notifier or just periodically) you can append the data to a single record.
    Open the file, set the file position to the end, write the data and close the file.
    Hope this helps

  • I can not write in Hebrew And create effects It shows all distorted  When This problem solved?

    I can not write in Hebrew
    And create effects
    It shows all distorted
    When This problem solved?

    roeisarusi wrote:
    When This problem solved?
    Nobody knows.  iWorks apps have always had bugs that make them unsuitable for Hebrew/Arabic for most people.  Tell Apple here:
    http://www.apple.com/feedback/keynote.html

  • After update ios. iPhone asks me to write the password and id which i dont know

    hello! I have a problem with my iphone 5 ,after update ios.Iphone asks me to write the password and id which i dont know because all settings set  in Egypt when i bought IPHONE.Is it possible to change id or make smth with this problem? I bought the Iphone in Egypt
    serial nomber F1*******TWH
    IMEI *****
    <Edited By Host>

    Vyacheslav1987 wrote:
    I unfortunatly could`t to contact with seller
    Then you will not be able to use the iPhone.
    Is it possible to change id or make smth with this problem?
    Not unless you have the previous owner's AppleID and password or can contact them.
    Sorry but why i can `t use my IPHONE?
    Because it is Activation locked.
    See this -> Find My iPhone Activation Lock: Removing a device from a previous owner’s account

  • Writing the file using Write to SGL and reading the data using Read from SGL

    Hello Sir, I have a problem using the Write to SGL VI. When I am trying to write the captured data using DAQ board to a SGL file, I am unable to store the data as desired. There might be some problem with the VI which I am using to write the data to SGL file. I am not able to figure out the minor problem I am facing.  I am attaching a zip file which contains five files.
    1)      Acquire_Current_Binary_Exp.vi -> This is the VI which I used to store my data using Write to SGL file.
    2)      Retrive_BINARY_Data.vi -> This is the VI which I used to Read from SGL file and plot it
    3)      Binary_Capture -> This is the captured data using (1) which can be plotted using (2) and what I observed is the plot is different and also the time scare is not as expected.
    4)      Unexpected_Graph.png is the unexpected graph when I am using Write to SGL and Read from SGL to store and retrieve the data.
    5)      Expected_Graph.png -> This is the expected data format I supposed to get. I have obtained this plot when I have used write to LVM and read from LVM file to store and retrieve the data.
    I tried a lot modifying the sub VI’s but it doesn’t work for me. What I think is I am doing some mistake while I am writing the data to SGL and Reading the data from SGL. Also, I don’t know the reason why my graph is not like (5) rather I am getting something like its in (4). Its totally different. You can also observe the difference between the time scale of (4) and (5).
    Attachments:
    Krishna_Files.zip ‏552 KB

    The binary data file has no time axis information, it is pure y data. Only the LVM file contains information about t(0) and dt. Since you throw away this information before saving to the binary file, it cannot be retrieved.
    Did you try wiring a 2 as suggested?
    (see also http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=925 )
    Message Edited by altenbach on 07-29-2005 11:35 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Retrive_BINARY_DataMOD2.vi ‏1982 KB

  • I used pages to write a resume and the company wants it in pdf format.  How do I do that?

    I USED PAGES TO WRITE A RESUME AND THE COMPANY WANTS IT IN pdf FORMAT. hOW DO I DO THAT?

    file > export > pdf

  • Write-Behind Caching and Limited Internal Cache Size

    Let's say I have a write-behind cache and configure its internal cache to be of a fixed limited size, e.g. 10000 units. What would happen if more than 10000 units are added to the write-behind cache within the write-delay period? Would my CacheStore's storeAll() get all of the added values or would some of the values be missed because of the internal cache size limitation?

    Hi Denis,     >
         > If an entry is removed while it is still in the
         > write-behind queue, it will be removed from the queue
         > and CacheStore.store(oKey, oValue) will be invoked
         > immediately.
         >
         > Regards,
         > Dimitri
         Dimitri,
         Just to confirm, that I understand it right if there is a queued update to a key which is then remove()-ed from the cache, then the following happens:
         First CacheStore.store(key, queuedUpdateValue) is invoked.
         Afterwards CacheStore.erase(key) is invoked.
         Both synchronously to the remove() call.
         I expected only erase will be invoked.
         BR,
         Robert

  • Thunderbird mail now looking up "CONTAINS" when attempting to write an email and not "BEGINS WITH"!!!! HELP!!!

    The NEW Thunderbird is looking up "CONTAINS" when attempting to write an email and not "BEGINS WITH" as it used to do before. I'm currently on 31.3.0 Thunderbird. Which version do I need to revert to, to get this function back for an employee on his PC??
    Thank you in advance and I await your reply,
    ~Mario

    Version 24

  • Can't write my user and password when accessing OV...

    Hi all,
    can somebody help me to resolve my issue
    when i access OVI, i am requested to  enter user and password, but when i write my user and password, it looks like i am writing in white caracters , i can't see what i am writing.
    thx for all and regards

    are you using predictive text ?what phone have you ?you can use the hash key to change characters
    If  i have helped at all a click on the white star below would be nice thanks.
    Now using the Lumia 1520

  • Hi, I need to install Adobe Flash Player because the version I have installed in my Mac Os is old, but I can´t because I need to write my email and my password and I don´t remember my password, so what can I do?

    Hi, I need to install Adobe Flash Player because the version I have installed in my Mac Os is old, but I can´t do it because I need to write my email and my password and I don´t remember my password, so what can I do? Thank you

    The email and password will be the ones for your computer's security, not something for any Adobe product.  You might need to consult Mac customer support if you are unable to determine the required information.

  • Nodata in the [DiskRead and Write]&[Network Received and Transmitted] of the reports

    Hello everyone!
    I'm a newbie.
    The problem is the column of [DiskRead and Write]&[Network Received and Transmitted] has nodata.The others are OK(CPU,Memory etc.).  I already set the base rate for [DiskRead and Write]&[Network Received and Transmitted]  and I do some operations like copy files from one to another VM in the VM. But it still 0.00 in the report .
    Can anybody tell me why? Is anything wrong in my vCenter Database?
    Thank you very much!

    Hello,
    Thanks for sending the data.
    The query that we asked you to run gives the values of network transmit-receive and disk read-write that CBM data collector has collected from VC.
    A closer look at the output of the query shows that CBM has been able to collect data for network received and transmit (resource_id=6) from VC. The attached report contains costs for network received and transmit.
    But there is no data for disk read and write (resource_id=2). So the report shows 0 costs for disk read and write.
    Now we need to know the cause of  absence of this data from CBM DB. As a first step, we will like to see if VC DB contains disk read-write related data. Can you please attach the output of following steps?
    1)  Please run following query on CBM DB
    select entity_moid from cb_vc_entity where vc_entity_id=(select vc_entity_id from cb_vc_entity_mapping where cb_entity_id=(select entity_id from cb_entity where entity_name='work_GJL'))
    This will give 'moid'. This moid should be used in the next query.
    2) Please run following queries on VC DB.
    We need outputs from 4 tables namely:
    i) VPXV_HIST_STAT_YEARLY
    ii) VPXV_HIST_STAT_MONTHLY
    iii) VPXV_HIST_STAT_WEEKLY
    iv) VPXV_HIST_STAT_DAILY
    Substitute <table name> in the following query with each one of these and store the outputs of different queries independently and attach here.
    select SAMPLE_TIME, SAMPLE_INTERVAL, STAT_VALUE from <table name> where ENTITY LIKE 'moid from above query' AND STAT_NAME = 'usage' and STAT_GROUP = 'disk' and STAT_ROLLUP_TYPE = 'average' order by SAMPLE_TIME
    Thanks,
    Mugdha

  • Automatic "Write Keyword Tags and Properties Info To Photo"?

    I have PSE8 and one of the reasons I stopped using it was because I had to periodically do a manual "Write Keyword Tags and Properties Info to Photo" so that all the metadata stays with my photos and isn't bound to just the PSE database.  This was very tedious to try and select just the files since I last performed a manual write not to mention if any older files were changed that I didn't know about.
    I see that the caption/title is automatically written to the files when changed but ratings and keywords are not.  Why isn't there any option to write everything automatically when changed?  Is this still the case with PSE9?  Thanks.

    That would take care of newly imported photos but what if someone added a keyword tag later to a photo from several months ago and I didn't know about it.
    No, this takes care of ALL files
    The only way to make sure all are covered is to select all photos in my catalog ...
    This is exactly what 99jon suggested
    ... and write tags which would result in thousands of unnecessary writes.
    If there's no new tag information, then nothing will get written (and even if it did, what's the harm, a photo had 3 tags before, and now it has the exact same 3 tags...)

Maybe you are looking for

  • CR 2008 report not displaying until Group Tree clicked

    We are having an issue with our CR 2008 web based reports.  The reports run correctly locally, but not when launched from a Windows 2008 Server on which we installed Crystal Reports 2008 Fix Pack 3.3 - Redist Install.  This is a web based application

  • Mailing Ringtones From PC to GZ One Ravine 2

    My dad just got a GZ One Ravine 2 and we'd like to put a ringtone on it.  I have one that I created with http://makeownringtone.com/ and they've always worked on my phone which is a Samsung Brightside.  All I have to do is send the ringtone I've crea

  • Data Visualization: Unable to set Marker Size

    JDeveloper Version: 11g Preview 3 I have an advanced graph component (dvt:graph) with GraphType set to COMBINATION_VERT_ABS_2Y. I am using this to display two numeric values one each on Y1 and Y2. Y1 values are displayed as a bar graph and Y2 as a li

  • View DW html web pages in Bridge?

    My apologies if this is deemed as a "double post", but my question has been on the Bridge Forum for over a week with no response. Hopefully someone can assist. Am I able to view htm / html web pages from my Dreamweaver local site as thumbnail preview

  • Want to upgrade system RAM of preserio V 6500 presently it is 1 GB only (512 x 2)

    want to upgrade system RAM of preserio V 6500 presently it is 1 GB only (512 x 2)