Camera Image Display - changing width and height.

Ok, so I wrote this simple program, but for some reason i cant control the offsets, width and height (attributes related to the image display on front panel). When i go to MAX, i am able to change these attributes, why cant i do it in labview? Any ideas?

You need to put the width and height controls inside your loop to adjust while running. 
From the image you provided, the width and height are set once outside the loop, and then you sit in the loop, so they can't be adjusted again.

Similar Messages

  • Draw rotated image to given width and height

    Problem, if an image where width and height aren't equal is rotated and drawn again, the image is not drawn (stretched) to the full width.
    Below is an example to illustrate my problem. The top image is stretched to the full width, the other aint.
    Example picture: http://www.google.nl/intl/nl_nl/images/logo.gif
    What am I doing wrong??
    Greet Retep
    import java.awt.Font;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.geom.AffineTransform;
    import java.awt.image.AffineTransformOp;
    import java.awt.image.BufferedImage;
    import java.awt.image.BufferedImageOp;
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JComponent;
    public class Test2 extends Frame{
         public static void main(String[] args)
              try {
                   new Test2();
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public Test2() {
              super("Rotate picture");
              add(new RotateTest());
            addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
            setFont(new Font("default", Font.PLAIN, 24));
            setSize(300, 300);
            setVisible(true);
         class RotateTest extends JComponent {
             public void paint(Graphics g) {
                 Graphics2D g2d = (Graphics2D)g;
                 try {
                        BufferedImage image = ImageIO.read(new BufferedInputStream(new FileInputStream("C:/logo.gif")));
                        AffineTransform affineTransForm = new AffineTransform();
                      affineTransForm.rotate(Math.toRadians(270), image.getWidth(), 0); 
                      //flip
                      //affineTransForm.translate(0, image.getHeight());
                      //affineTransForm.scale(1, -1);
                      BufferedImageOp bufferedImageOp = new AffineTransformOp(affineTransForm,
                              AffineTransformOp.TYPE_BICUBIC);
                      BufferedImage image2 = bufferedImageOp.filter(image, null);
    //                  BufferedImage tempImage = new BufferedImage(image.getWidth(),image.getHeight(), image2.getType());
    //                Graphics2D graphics2D = tempImage.createGraphics();
    //                graphics2D.drawImage(image2, 0, 0, null);
    //                graphics2D.dispose();
                      g2d.drawImage(image, 5, 15, 280, 50, null);
                      g2d.drawImage(image2, 5, 70, 280, 50, null);
                      //g2d.drawImage(tempImage, 5, 125, 280, 50, null);
                      //g2d.drawImage(image, affineTransForm, null);
                      g2d.drawRect(5, 15, 280, 50);
                      g2d.drawRect(5, 70, 280, 50);
                   } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                   } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
    }

    Let's see if this helps...
    import java.awt.Font;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Rectangle2D;
    import java.awt.image.BufferedImage;
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JComponent;
    public class T2Rx extends Frame {
        public static void main(String[] args) {
            try {
                new T2Rx();
            } catch (Exception e) {
               e.printStackTrace();
        public T2Rx() {
            super("Rotate picture");
            add(new RotateTest());
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            setFont(new Font("default", Font.PLAIN, 24));
            setSize(300, 375);
            setLocation(200,200);
            setVisible(true);
        class RotateTest extends JComponent {
            BufferedImage image;
            RotateTest() {
                // You only need to do this one time. Save the image in a
                // a member variable so you can access it whenever you want.
                try {
                    image = ImageIO.read(new BufferedInputStream(
                                         new FileInputStream("logo.gif")));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
            protected void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D)g;
                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                    RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                int w = getWidth();
                int h = getHeight();
                BufferedImage scaled = scaleTo(image, 280, 50);
                int iw = scaled.getWidth();
                int ih = scaled.getHeight();
                double x = (w - iw)/2.0;
                double y = 1;
                g2.drawImage(scaled, (int)x, (int)y, this);
                g2.draw(new Rectangle2D.Double(x, y, iw, ih));
                double theta = Math.PI*3/2;
                x = (w - ih)/2.0;
                y = (ih + iw)/2.0 + 1;
                AffineTransform at = AffineTransform.getTranslateInstance(x, y);
                at.rotate(theta, iw/2.0, ih/2.0);
                g2.drawRenderedImage(scaled, at);
                g2.draw(at.createTransformedShape(new Rectangle2D.Double(0, 0, iw, ih)));
        private BufferedImage scaleTo(BufferedImage src, int w, int h) {
            //System.out.printf("type = %d%n", src.getType());
            // This type gives a better appearance after scaling.
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage out = new BufferedImage(w, h, type);
            Graphics2D g2 = out.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.setBackground(getBackground());
                             //java.awt.Color.pink);  // just checking
            g2.clearRect(0, 0, w, h);
            double xScale = (double)w/src.getWidth();
            double yScale = (double)h/src.getHeight();
            double scale = Math.min(xScale, yScale);    // scale to fit
                           //Math.max(xScale, yScale);  // scale to fill
            double x = (w - scale*src.getWidth())/2;
            double y = (h - scale*src.getHeight())/2;
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            at.scale(scale, scale);
            g2.drawRenderedImage(src, at);
            g2.dispose();
            return out;
    }

  • Change width and height

    Hello, how can i change widht and hight on iWeb?

    welcome to the forum, to change anything in iweb use the inspector panel. Choose page - layout to alter the width and height. The inspector panel is at the bottom of the page and the page set-up is the second icon along the top of the panel. Hope that makes sense and gets you up and running.

  • Change width and height in a rich symbol

    Hi!
    I'm trying to build a rich symbol in fw cs4 so I can use it in multiple projects and I'd need some boxes to scale to certain sizes I would assign through the properties panel.
    Is it possible? I've seen in former versions that both width and height are read-only but I can't find anything for current version.
    Also, if possible, can I set the x and y position?
    What I've been trying is:
    box.height = height;
    box.width  = width;
    where box is an element (I've changed other properties and it works) and height and width are values (which also work)
    Thanks a lot

    I need to know if this is possible, too!
    Hopefully this is working somehow.
    Thanks

  • How to change the width and height of the visible part of the of the report

    I have define a report with paper size 'Letter', orientation 'landscape' and 30 columns. Dynamically I am changing width of columns and suppressing many columns of the report.
    Mostly using first 16-20 columns and others get suppressed.
    Now problem is that when navigating the report thru crystal viewer, a huge blank spaces getting display on right of the report. When we take jump to some part of report thru navigation tree, the whole report gets shifted to left and only blank part is visible and it is required to scroll left.
    Even printing is not working correctly.
    Is there any way to change the width and height of the visible part of the report in the viewer thru .net classes? Setting the width and height of the report in Load event handler doesn't help.  
    Example: CrystalReportViewer1.Width = 200; - is not helping.
    Is there any other solution?
    Please let me know.
    Thanks
    Mahesh Patel

    Hi Yogesh,
    Your suggestion 'reportDocument.PrintOptions.PaperSize=PaperSize.PaperLedger;' along with 'PaperOrientation' setting as follow works fine. I tried to switch between Landscape and Portrait depending on report width.
    reportDocument.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
    But problem with crystal viewer remain as it is.
    While navigating report thru crystal viewer, when we take jump to some part of report thru navigation tree, the whole report gets shifted to left and it is required to scroll left.
    Thanks for your very good suggestion.
    Mahesh Patel

  • How can I get the image width and height stored in database?

    Hi!I write s servlet to display images store in database.but how can I get the image width and height?

    Have you tryed using PJA or a similar library?
    I presume you get java.lang.NoClassDefFoundError on the line :
    Toolkit.getDefaultToolkit();?

  • Get image properties (width and height)

    Hi there,
    Does anyone know if there is a way that I could get the width and height of an image to be displayed in a JSP.

    Image has methods to get the width & height.

  • [svn:osmf:] 10085: Fixing video width and height getting reset when there' s no true dimensional change reported by 'onMetaData'.

    Revision: 10085
    Author:   [email protected]
    Date:     2009-09-09 07:39:54 -0700 (Wed, 09 Sep 2009)
    Log Message:
    Fixing video width and height getting reset when there's no true dimensional change reported by 'onMetaData'.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/openvideoplayer/video/VideoElement.as

    hi their i have tried your last code but their is a problem with it on my pc that when i click the send video button it gives the error related to vector,
    Vector deviceList = CaptureDeviceManager.getDeviceList()
    di = (CaptureDeviceInfo)deviceList.firstElement();
    returns zero.
    please help my email address is [email protected]
    kindly send me an email regarding the solution of my problem. i am using 'creative web cam' over XP windows.

  • Get width and height of a dynamically loaded image once it's done loading?!

    hello : :
    well... i'm taking my first shots at flex after programming
    in flash for a year now. it's been fun and i've been picking up on
    things pretty well (or so i think), but i come across something
    today that i used to be able to do in my as2 programming and don't
    know how to do in as3...
    in flex, i'm loading an image into an image control (by using
    "myImgControl.load(urlString)"). i have a "complete" parameter on
    the image control that calls a function just fine after the image
    is loaded, but if i try and check the hight and width of the loaded
    image once it loads, it comes back as zero. how can i get the
    height and width of the image after it's loaded?!
    in flash/as2 i used to do this little trick/work-around i
    found in a forum (kirupa.com, i think) to find out the width and
    height once the loaded image listener checked the loading process
    and came back "complete"... in the code below, "imgLoader" is the
    movieClip the image was loaded using
    imgLoaderListener.loadClip(urlString, imgLoader).
    quote:
    iTot = imgLoader.getBytesTotal();
    iLoad = imgLoader.getBytesLoaded();
    if (iLoad == iTot && iTot > 4) {
    imgH = imgLoader._height;
    imgW = imgLoader._width;
    that all make sense?!
    basically, it's as simple as this: i need to find something
    similar to the above for as3 that will tell me the width and height
    of a dynamically loaded image after it's done loading...
    so there ya have it. i appreciate any help any of you can
    throw my way! thank you so much for even reading this!
    : : michael

    I assume you have probably already figured this out, but just
    in case, there should be an event to listen for after which you can
    get the height and width information successfully. I can't remember
    the exact name, however. Experiment and see which one works
    time-wise.

  • Java returning incorrect values for width and height of a Tiff image

    I have some TIFF images (sorry, I cannot post them b/c of there confidential nature) that are returning the incorrect values for the width and height. I am using Image.getWidth(null) and have tried the relevant methods from BufferedImage. When I open the same files in external viewers (Irfanview, MS Office Document Imaging) they look fine and report the "correct" dimensions. When I re-save the files, my code works fine. Obviously, there is something wrong with the files, but why would the Java code fail and not the external viewers? Is there some way I can detect file problems?
    Here is the code, the relevant section is in the print() routine.
    * ImagePrinter.java
    * Created on Feb 27, 2008
    * Created by tso1207
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.print.PageFormat;
    import java.awt.print.PrinterException;
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.FileImageInputStream;
    import javax.imageio.stream.ImageInputStream;
    import com.shelter.io.FileTypeIdentifier;
    public class ImagePrinter extends FilePrintable
       private final ImageReader _reader;
       private final int _pageCount;
       private final boolean _isTiff;
       //for speed we will hold current page info in memory
       private Image _image = null;
       private int _imgWidth = 0;
       private int _imgHeight = 0;
       private int _currentPage = -1;
       public ImagePrinter(File imageFile) throws IOException
          super(imageFile);
          ImageInputStream fis = new FileImageInputStream(getFile());
          Iterator readerIter = ImageIO.getImageReaders(fis);
          ImageReader reader = null;
          while (readerIter.hasNext())
             reader = (ImageReader) readerIter.next();
          reader.setInput(fis);
          _reader = reader;
          int pageCount = 1;
          String mimeType = FileTypeIdentifier.getMimeType(imageFile, true);
          if (mimeType.equalsIgnoreCase("image/tiff"))
             _isTiff = true;
             pageCount = reader.getNumImages(true);
          else
             _isTiff = false;
          _pageCount = pageCount;
       public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
          throws java.awt.print.PrinterException
          int drawX = 0, drawY = 0;
          double scaleRatio = 1;
          if (getCurrentPage() != (pageIndex - getPageOffset()))
             try
                setCurrentPage(pageIndex - getPageOffset());
                setImage(_reader.read(getCurrentPage()));
                setImgWidth(getImage().getWidth(null));
                setImgHeight(getImage().getHeight(null));
             catch (IndexOutOfBoundsException e)
                return NO_SUCH_PAGE;
             catch (IOException e)
                throw new PrinterException(e.getLocalizedMessage());
             if (!_isTiff && getImgWidth() > getImgHeight())
                pf.setOrientation(PageFormat.LANDSCAPE);
             else
                pf.setOrientation(PageFormat.PORTRAIT);
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(pf.getImageableX(), pf.getImageableY());
          g2.setClip(0, 0, (int) pf.getImageableWidth(), (int) pf.getImageableHeight());
          scaleRatio =
             (double) ((getImgWidth() > getImgHeight())
                ? (pf.getImageableWidth() / getImgWidth())
                : (pf.getImageableHeight() / getImgHeight()));
          //check the scale ratio to make sure that we will not write something off the page
          if ((getImgWidth() * scaleRatio) > pf.getImageableWidth())
             scaleRatio = (pf.getImageableWidth() / getImgWidth());
          else if ((getImgHeight() * scaleRatio) > pf.getImageableHeight())
             scaleRatio = (pf.getImageableHeight() / getImgHeight());
          int drawWidth = getImgWidth();
          int drawHeight = getImgHeight();
          //center image
          if (scaleRatio < 1)
             drawX = (int) ((pf.getImageableWidth() - (getImgWidth() * scaleRatio)) / 2);
             drawY = (int) ((pf.getImageableHeight() - (getImgHeight() * scaleRatio)) / 2);
             drawWidth = (int) (getImgWidth() * scaleRatio);
             drawHeight = (int) (getImgHeight() * scaleRatio);
          else
             drawX = (int) (pf.getImageableWidth() - getImgWidth()) / 2;
             drawY = (int) (pf.getImageableHeight() - getImgHeight()) / 2;
          g2.drawImage(getImage(), drawX, drawY, drawWidth, drawHeight, null);
          g2.dispose();
          return PAGE_EXISTS;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since version XXX
        * @return
       public int getPageCount()
          return _pageCount;
       public void destroy()
          setImage(null);
          try
             _reader.reset();
             _reader.dispose();
          catch (Exception e)
          System.gc();
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public Image getImage()
          return _image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgHeight()
          return _imgHeight;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgWidth()
          return _imgWidth;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param image
       public void setImage(Image image)
          _image = image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgHeight(int i)
          _imgHeight = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgWidth(int i)
          _imgWidth = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getCurrentPage()
          return _currentPage;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setCurrentPage(int i)
          _currentPage = i;
    }Edited by: jloyd01 on Jul 3, 2008 8:26 AM

    Figured it out. The files have a different vertical and horizontal resolutions. In this case the horizontal resolution is 200 DPI and the vertical is 100 DPI. The imgage width and height values are based on those resolution values. I wrote a section of code to take care of the problem (at least for TIFF 6.0)
       private void setPageSize(int pageNum) throws IOException
          IIOMetadata imageMetadata = _reader.getImageMetadata(pageNum);
          //Get the IFD (Image File Directory) which is the root of all the tags
          //for this image. From here we can get all the tags in the image.
          TIFFDirectory ifd = TIFFDirectory.createFromMetadata(imageMetadata);
          double xPixles = ifd.getTIFFField(256).getAsDouble(0);
          double yPixles = ifd.getTIFFField(257).getAsDouble(0);
          double xRes = ifd.getTIFFField(282).getAsDouble(0);
          double yres = ifd.getTIFFField(283).getAsDouble(0);
          int resUnits = ifd.getTIFFField(296).getAsInt(0);
          double imageWidth = xPixles / xRes;
          double imageHeight = yPixles / yres;
          //if units are in CM convert ot inches
          if (resUnits == 3)
             imageWidth = imageWidth * 0.3937;
             imageHeight = imageHeight * 0.3937;
          //convert to pixles in 72 DPI
          imageWidth = imageWidth * 72;
          imageHeight = imageHeight * 72;
          setImgWidth((int) Math.round(imageWidth));
          setImgHeight((int) Math.round(imageHeight));
          setImgAspectRatio(imageWidth / imageHeight);
       }

  • Finding the width and height of an image

    Hi...
    i have a path to an image "images/me.gif" and i'm trying to find its width and height.. am trying to use javax.swing.ImageIcon but it refuses to recognise the constructor with just the filename (string) parameter, and needs a URL to the file... anyone knows what i'm doing wrong??? is this the wrong class that i'm using...!??!?!?!?!?

    String filename = "images/me.gif";
    Image myImage = carregarImagem(filename);
    System.out.println(myImage.getWidth(this));
    System.out.println(myImage.getHeight(this));
    * M�todo que carrega imagens na mem�ria, a partir da URL onde o
    * applet est� sendo carregado. O uso de um 'mediaTracker' � fundamental para
    * evitar problemas quanto � velocidade de carga de uma imagem. Se voc� n�o
    * usar um mediaTracker, o seu c�digo pode tentar usar uma imagem antes dela
    * estar plenamente carregada na mem�ria, o que causaria um erro de execu��o.
    * @param nomeDaImagem O nome da imagem a ser carregada
    * @return A imagem requisitada ou null caso n�o haja tal imagem na url do applet
    public Image carregarImagem(String nomeDaImagem)
                   try
                                   Image imagem = getImage(getDocumentBase(), nomeDaImagem);
                                   MediaTracker carregador = new MediaTracker(this);
                                   carregador.addImage(imagem, 0);
                                   carregador.waitForID(0);
                                   return imagem;
                   catch(Exception erro)
                                   erro.printStackTrace();
                                   System.exit(0);
                                   return null;

  • Fit the image to window width, window height and  the window size

    hi all
    here we wrote the code for "fit the image to window width, window height and the window size". we are facing some problems in it. and all these operations have to perform even after zooming operations are done.if the below code doesnt satisfy kindly provide appropriate code .
    thanks .
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.io.File;
    import javax.swing.filechooser.FileFilter;
    import java.awt.geom.*;
    public class DP extends JFrame implements ActionListener,
                                               MouseListener,
                                               MouseMotionListener {
        private final int PEN_OP = 1;
        private final int CLEAR_OP = 2;
        private int radius;
        private int radius1;
        private int mousex = 0;
        private int mousey = 0;
        private int prevx = 0;
        private int prevy = 0;
        private boolean initialFreeHand = true;
        private boolean initialLine = true;
        private boolean initialEraser = true;
        private int Orx = 0;
        private int Ory = 0;
        private int OrWidth = 0;
        private int OrHeight = 0;
        private int drawX = 0;
        private int drawY = 0;
        private int polyX = 0;
        private int polyY = 0;
        private int eraserLength = 5;
        private int udefRedValue = 255;
        private int udefGreenValue = 255;
        private int udefBlueValue = 255;
        private int opStatus = PEN_OP;
        private int colorStatus = 1;
        private double zoomPercentage=10;
        private Color mainColor = new Color(0, 0, 0);
        private Color xorColor = new Color(255, 255, 255);
        private Color userDefinedColor =
            new Color(udefRedValue, udefGreenValue,udefBlueValue);
        private JButton openButton = new JButton("open");
        private JButton closeButton = new JButton("close");
         private JButton zoominButton = new JButton("ZoomIn");
         private JButton zoomoutButton = new JButton("ZoomOut");
         private JButton zoomto100Button = new JButton("ZoomTo100");
         private JButton fwwButton = new JButton("Fit window width");
         private JButton fwhButton = new JButton("Fit window height");
         private JButton fwButton = new JButton("Fit the window");
        private JButton clearButton = new JButton("Clear");
        private JTextField colorStatusBar = new JTextField(20);
        private JTextField opStatusBar = new JTextField(20);
        private JTextField mouseStatusBar = new JTextField(10);
        private JPanel controlPanel = new JPanel(new GridLayout(18, 1, 0, 0));
        JToolBar jToolbar = new JToolBar();
        private Container container;
        private JScrollBar horizantalSlide=new JScrollBar();
        public BufferedImage image;
        BufferedImage bgImage;
    //    public ImageIcon icon=null;
        JFileChooser fileChooser;
        DrawPanel drawPanel = new DrawPanel(bgImage,zoomPercentage);
        public DP() {
            super("WhiteBoard");
            fileChooser = new JFileChooser(".");
            container = getContentPane();
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
            container.add(jToolbar,BorderLayout.NORTH);
            container.add(horizantalSlide);
            jToolbar.add(openButton);
            jToolbar.add(closeButton);
              jToolbar.add(zoominButton);
              jToolbar.add(zoomoutButton);
              jToolbar.add(zoomto100Button);
              jToolbar.add(fwwButton);
              jToolbar.add(fwhButton);
              jToolbar.add(fwButton);
            jToolbar.add(clearButton);
            colorStatusBar.setEditable(false);
            opStatusBar.setEditable(false);
            mouseStatusBar.setEditable(false);
            controlPanel.setBackground(Color.white);
            drawPanel.setBackground(Color.white);
            container.add(controlPanel, "West");
            container.add(drawPanel, "Center");
            openButton.addActionListener(this);
            closeButton.addActionListener(this);
              zoominButton.addActionListener(this);
              zoomoutButton.addActionListener(this);
              zoomto100Button.addActionListener(this);
              fwwButton.addActionListener(this);
              fwhButton.addActionListener(this);
              fwButton.addActionListener(this);
            clearButton.addActionListener(this);
            drawPanel.addMouseMotionListener(this);
            drawPanel.addMouseListener(this);
            addMouseListener(this);
            addMouseMotionListener(this);
            opStatusBar.setText("FreeHand");
            colorStatusBar.setText("Black");
        public void actionPerformed(ActionEvent e) {
            if(e.getActionCommand().equals("open"))
                showDialog();
            if(e.getActionCommand().equals("close"))
                closeDialog();
              if(e.getActionCommand().equals("ZoomIn"))
                   drawPanel.zoom(1);
              if(e.getActionCommand().equals("ZoomOut"))
                   drawPanel.zoom(-1);
              if(e.getActionCommand().equals("ZoomTo100"))
                   drawPanel.zoom(+10);
              if(e.getActionCommand().equals("Fit window width"))
                   drawPanel.fitwindowwidth();
              if(e.getActionCommand().equals("Fit window height"))
                   drawPanel.fitwindowheight();
              if(e.getActionCommand().equals("Fit the window"))
                   drawPanel.fitthewindow();
            if (e.getActionCommand() == "Clear")
                opStatus = CLEAR_OP;
            switch (opStatus) {
                case CLEAR_OP:
                    clearPanel();
        private void showDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    bgImage = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("IO error: " + e.getMessage());
                clearPanel();
        private void closeDialog() {
            drawPanel.setVisible(false);
            drawPanel.repaint();
        public void clearPanel() {
            opStatusBar.setText("Clear");
            Graphics g = image.getGraphics();
            g.setColor(drawPanel.getBackground());
            g.fillRect(0, 0, drawPanel.getBounds().width, drawPanel.getBounds().height);
            if(bgImage != null)
                g.drawImage(bgImage, 0, 0, this);
            g.dispose();
            drawPanel.repaint();
        public boolean mouseHasMoved(MouseEvent e) {
            return (mousex != e.getX() || mousey != e.getY());
        public void setActualBoundry() {
            if (mousex < Orx || mousey < Ory) {
                if (mousex < Orx) {
                    OrWidth = Orx - mousex;
                    drawX = Orx - OrWidth;
                } else {
                    drawX = Orx;
                    OrWidth = mousex - Orx;
                if (mousey < Ory) {
                    OrHeight = Ory - mousey;
                    drawY = Ory - OrHeight;
                } else {
                    drawY = Ory;
                    OrHeight = mousey - Ory;
            } else {
                drawX = Orx;
                drawY = Ory;
                OrWidth = mousex - Orx;
                OrHeight = mousey - Ory;
        public void setGraphicalDefaults(MouseEvent e) {
            mousex = e.getX();
            mousey = e.getY();
            prevx = e.getX();
            prevy = e.getY();
            Orx = e.getX();
            Ory = e.getY();
            drawX = e.getX();
            drawY = e.getY();
            OrWidth = 0;
            OrHeight = 0;
        public void mouseDragged(MouseEvent e) {
            updateMouseCoordinates(e);
            switch (opStatus) {}
        public void mouseReleased(MouseEvent e) {
            updateMouseCoordinates(e);
            switch (opStatus) {}
        public void mouseEntered(MouseEvent e) {
            updateMouseCoordinates(e);
        public void updateMouseCoordinates(MouseEvent e) {
            String xCoor = "";
            String yCoor = "";
            if (e.getX() < 0)
                xCoor = "0";
            else {
                xCoor = String.valueOf(e.getX());
            if (e.getY() < 0)
                xCoor = "0";
            else {
                yCoor = String.valueOf(e.getY());
            mouseStatusBar.setText("x:" + xCoor + " y:" + yCoor);
        public void mouseClicked(MouseEvent e) { updateMouseCoordinates(e); }
        public void mouseExited(MouseEvent e) { updateMouseCoordinates(e); }
        public void mouseMoved(MouseEvent e) { updateMouseCoordinates(e); }
        public void mousePressed(MouseEvent e) { updateMouseCoordinates(e); }
        public static void main(String[] args) {
            DP wb = new DP();
            wb.setDefaultCloseOperation(EXIT_ON_CLOSE);
            wb.setSize(1024,740);
            wb.setVisible(true);
        private class DrawPanel extends JPanel {
            private double m_zoom = 1.0;
            private double m_zoomPercentage;
            private BufferedImage m_image;
            double theta = 0;
            double thetaInc = Math.PI/2;
            public DrawPanel(BufferedImage imageb,double zoomPercentage) {
                m_image = imageb;
                m_zoomPercentage = zoomPercentage / 100;
            protected void paintComponent(Graphics g) {
                Graphics2D g2d=(Graphics2D)g;
                if(image == null)
                    initImage();
                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                     RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                double x = (1.0 - m_zoom)*getWidth()/2.0;
                double y = (1.0 - m_zoom)*getHeight()/2.0;
                AffineTransform at = AffineTransform.getTranslateInstance(x, y);
                at.rotate(theta,m_zoom*getWidth()/2,m_zoom*getHeight()/2);
                at.scale(m_zoom, m_zoom);
                g2d.drawRenderedImage(image, at);
      public void zoom(int inc) {
            m_zoom += inc * m_zoomPercentage;
            repaint();
              public void fitwindowwidth()
                int w1=drawPanel.getWidth();
                int h1=drawPanel.getHeight();
                BufferedImage image2=image.getScaledInstance(w1,h1,Image.SCALE_DEFAULT);
                drawPanel.setPreferredSize(new java.awt.Dimension(100,image2.getImage().getHeight(null)));
               drawPanel.repaint();
              public void fitwindowheight()
           BufferedImage image2=image.getScaledInstance(500,680,1); 
           drawPanel.setImage(iicon);
           drawPanel.setPreferredSize(new java.awt.Dimension(100,image2.getImage().getHeight(null)));
           drawPanel.repaint();
              public void fitthewindow()
           BufferedImage image2=image.getScaledInstance(1000,680,1);
           drawPanel.setPreferredSize(new java.awt.Dimension(100,image2.getImage().getHeight(null)));
           drawPanel.repaint();
            private void initImage() {
                int w = getWidth();
                int h = getHeight();
                image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Graphics2D g2 = image.createGraphics();
                g2.setPaint(getBackground());
                g2.fillRect(0,0,w,h);
                g2.dispose();
    }

    thank you for giving reply.
    your code is very helpful to us.but i couldn't integrate it in my code.here's my code.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.io.File;
    import javax.swing.filechooser.FileFilter;
    import java.awt.geom.*;
    public class IS extends JFrame implements ActionListener,
                                               MouseListener,
                                               MouseMotionListener {
        private final int PEN_OP = 1;
        private final int CLEAR_OP = 2;
         private     final int DISTORT = 3;
        private final int SCALE   = 4;
        private final int FIT     = 5;
        private final int FILL    = 6;
        int scaleMode = SCALE;
        private int radius;
        private int radius1;
        private int mousex = 0;
        private int mousey = 0;
        private int prevx = 0;
        private int prevy = 0;
        private boolean initialFreeHand = true;
        private boolean initialLine = true;
        private boolean initialEraser = true;
        private int Orx = 0;
        private int Ory = 0;
        private int OrWidth = 0;
        private int OrHeight = 0;
        private int drawX = 0;
        private int drawY = 0;
        private int polyX = 0;
        private int polyY = 0;
        private int eraserLength = 5;
        private int udefRedValue = 255;
        private int udefGreenValue = 255;
        private int udefBlueValue = 255;
        private int opStatus = PEN_OP;
        private int colorStatus = 1;
        private double zoomPercentage=10;
        private Color mainColor = new Color(0, 0, 0);
        private Color xorColor = new Color(255, 255, 255);
        private Color userDefinedColor =
            new Color(udefRedValue, udefGreenValue,udefBlueValue);
        private JButton openButton = new JButton("open");
        private JButton closeButton = new JButton("close");
         private JButton zoominButton = new JButton("ZoomIn");
         private JButton zoomoutButton = new JButton("ZoomOut");
         private JButton zoomto100Button = new JButton("ZoomTo100");
         private JButton fwwButton = new JButton("Fit window width");
         private JButton fwhButton = new JButton("Fit window height");
         private JButton fwButton = new JButton("Fit the window");
        private JButton clearButton = new JButton("Clear");
        private JTextField colorStatusBar = new JTextField(20);
        private JTextField opStatusBar = new JTextField(20);
        private JTextField mouseStatusBar = new JTextField(10);
        private JPanel controlPanel = new JPanel(new GridLayout(18, 1, 0, 0));
        JToolBar jToolbar = new JToolBar();
        private Container container;
        private JScrollBar horizantalSlide=new JScrollBar();
        public BufferedImage image;
        BufferedImage bgImage;
    //    public ImageIcon icon=null;
        JFileChooser fileChooser;
        DrawPanel drawPanel = new DrawPanel(bgImage,zoomPercentage);
        public IS() {
            super("WhiteBoard");
            fileChooser = new JFileChooser(".");
            container = getContentPane();
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
            container.add(jToolbar,BorderLayout.NORTH);
            container.add(horizantalSlide);
            jToolbar.add(openButton);
            jToolbar.add(closeButton);
              jToolbar.add(zoominButton);
              jToolbar.add(zoomoutButton);
              jToolbar.add(zoomto100Button);
              jToolbar.add(fwwButton);
              jToolbar.add(fwhButton);
              jToolbar.add(fwButton);
            jToolbar.add(clearButton);
            colorStatusBar.setEditable(false);
            opStatusBar.setEditable(false);
            mouseStatusBar.setEditable(false);
            controlPanel.setBackground(Color.white);
            drawPanel.setBackground(Color.white);
            container.add(controlPanel, "West");
            container.add(drawPanel, "Center");
            openButton.addActionListener(this);
            closeButton.addActionListener(this);
              zoominButton.addActionListener(this);
              zoomoutButton.addActionListener(this);
              zoomto100Button.addActionListener(this);
              fwwButton.addActionListener(this);
              fwhButton.addActionListener(this);
              fwButton.addActionListener(this);
            clearButton.addActionListener(this);
            drawPanel.addMouseMotionListener(this);
            drawPanel.addMouseListener(this);
            addMouseListener(this);
            addMouseMotionListener(this);
            opStatusBar.setText("FreeHand");
            colorStatusBar.setText("Black");
        public void actionPerformed(ActionEvent e) {
            if(e.getActionCommand().equals("open"))
                showDialog();
            if(e.getActionCommand().equals("close"))
                closeDialog();
              if(e.getActionCommand().equals("ZoomIn"))
                   drawPanel.zoom(1);
              if(e.getActionCommand().equals("ZoomOut"))
                   drawPanel.zoom(-1);
              if(e.getActionCommand().equals("ZoomTo100"))
                   drawPanel.zoom(+10);
              if(e.getActionCommand().equals("Fit window width"))
                   //drawPanel.fitwindowwidth();
              drawPanel.scaleImage(0,0,0,0);
              if(e.getActionCommand().equals("Fit window height"))
              drawPanel.scaleImage(0,0,0,0);
              if(e.getActionCommand().equals("Fit the window"))
              drawPanel.scaleImage(0,0,0,0);
            if (e.getActionCommand() == "Clear")
                opStatus = CLEAR_OP;
            switch (opStatus) {
                case CLEAR_OP:
                    clearPanel();
        private void showDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    bgImage = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("IO error: " + e.getMessage());
                clearPanel();
        private void closeDialog() {
            drawPanel.setVisible(false);
            drawPanel.repaint();
        public void clearPanel() {
            opStatusBar.setText("Clear");
              int w = image.getWidth();
            int h = image.getHeight();
            Graphics g = image.getGraphics();
            g.setColor(drawPanel.getBackground());
            g.fillRect(0, 0, w, h);
            if(bgImage != null) {
                int x = (w - bgImage.getWidth())/2;
                int y = (h - bgImage.getHeight())/2;
                g.drawImage(bgImage, x, y, this);
            g.dispose();
            drawPanel.repaint();
        public boolean mouseHasMoved(MouseEvent e) {
            return (mousex != e.getX() || mousey != e.getY());
        public void setActualBoundry() {
            if (mousex < Orx || mousey < Ory) {
                if (mousex < Orx) {
                    OrWidth = Orx - mousex;
                    drawX = Orx - OrWidth;
                } else {
                    drawX = Orx;
                    OrWidth = mousex - Orx;
                if (mousey < Ory) {
                    OrHeight = Ory - mousey;
                    drawY = Ory - OrHeight;
                } else {
                    drawY = Ory;
                    OrHeight = mousey - Ory;
            } else {
                drawX = Orx;
                drawY = Ory;
                OrWidth = mousex - Orx;
                OrHeight = mousey - Ory;
        public void setGraphicalDefaults(MouseEvent e) {
            mousex = e.getX();
            mousey = e.getY();
            prevx = e.getX();
            prevy = e.getY();
            Orx = e.getX();
            Ory = e.getY();
            drawX = e.getX();
            drawY = e.getY();
            OrWidth = 0;
            OrHeight = 0;
        public void mouseDragged(MouseEvent e) {
            updateMouseCoordinates(e);
            switch (opStatus) {
        public void mouseReleased(MouseEvent e) {
            updateMouseCoordinates(e);
            switch (opStatus) {}
        public void mouseEntered(MouseEvent e) {
            updateMouseCoordinates(e);
        public void updateMouseCoordinates(MouseEvent e) {
            String xCoor = "";
            String yCoor = "";
            if (e.getX() < 0)
                xCoor = "0";
            else {
                xCoor = String.valueOf(e.getX());
            if (e.getY() < 0)
                xCoor = "0";
            else {
                yCoor = String.valueOf(e.getY());
            mouseStatusBar.setText("x:" + xCoor + " y:" + yCoor);
        public void mouseClicked(MouseEvent e) { updateMouseCoordinates(e); }
        public void mouseExited(MouseEvent e) { updateMouseCoordinates(e); }
        public void mouseMoved(MouseEvent e) { updateMouseCoordinates(e); }
        public void mousePressed(MouseEvent e) { updateMouseCoordinates(e); }
        public static void main(String[] args) {
            IS wb = new IS();
            wb.setDefaultCloseOperation(EXIT_ON_CLOSE);
            wb.setSize(1024,740);
            wb.setVisible(true);
        private class DrawPanel extends JPanel {
            private double m_zoom = 1.0;
            private double m_zoomPercentage;
            private BufferedImage m_image;
            double theta = 0;
            double thetaInc = Math.PI/2;
            public DrawPanel(BufferedImage imageb,double zoomPercentage) {
                m_image = imageb;
                m_zoomPercentage = zoomPercentage / 100;
            protected void paintComponent(Graphics g) {
                   super.paintComponent(g);
                Graphics2D g2d=(Graphics2D)g;
                if(image == null)
                    initImage();
                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                     RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                              int w = getWidth();
                    int h = getHeight();
                  int iw = image.getWidth();
                  int ih = image.getHeight();
                  if(scaleMode == SCALE) {
                double x = (w - m_zoom*iw)/2;
                double y = (h - m_zoom*ih)/2;
                AffineTransform at = AffineTransform.getTranslateInstance(x, y);
                at.rotate(theta,m_zoom*getWidth()/2,m_zoom*getHeight()/2);
                at.scale(m_zoom, m_zoom);
                g2d.drawRenderedImage(image, at);
                   else {
                scaleImage(w, h, iw, ih);
              private void scaleImage( int w, int h, int iw, int ih) {
                             Graphics2D g2d = image.createGraphics();
            double xScale = (double)w/iw;
            double yScale = (double)h/ih;
            AffineTransform at = new AffineTransform();
            if(scaleMode == DISTORT) {
                double x = (w - xScale*iw)/2;
                double y = (h - yScale*ih)/2;
                at.setToTranslation(x, y);
                at.scale(xScale, yScale);
            } else {
                double scale = (scaleMode == FIT) ? Math.min(xScale, yScale)
                                                  : Math.max(xScale, yScale);
                double x = (w - scale*iw)/2;
                double y = (h - scale*ih)/2;
                at.setToTranslation(x, y);
                at.scale(scale, scale);
            g2d.drawRenderedImage(image, at);
      public void zoom(int inc) {
            m_zoom += inc * m_zoomPercentage;
            repaint();
            private void initImage() {
                int w = getWidth();
                int h = getHeight();
                image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Graphics2D g2 = image.createGraphics();
                g2.setPaint(getBackground());
                g2.fillRect(0,0,w,h);
                g2.dispose();
    }

  • How to automate the changing of Width and Height of the document

    Hi,
    I just want to know if anyone already automate the changing of width and height of document(eps file).
    Thanks,
    Buddy

    Check out SetDocumentSetup from kAIDocumentSuite.

  • Change the width and height of Landscape Layout for a report in 10G

    Hi,
    I'm new to reports and when i built the report in report builder 10g, the layout orientation was 'Landscape', hence I assumed that it'll be a landscape layout.
    However, the width and height fields of the main section are 11 and 20 respectively. However, the height should ideally be 8.5. When i try to change it I get the following error message :
    Layout canvas must remain large enough to fit layout objects.
    Could you please tell me how to change the height of this landscape layout to 8.5 from 20.
    The report has several main frames within a repeating frame, since the same report has to run multiple times.
    Is it possible to have a repeating page across pages (crossing the horizontal margin) and hence have some of the main frames move down to the next page. I'm trying to do this to then be able to reduce the height of the main section of the report to 8.5. Its not working though because I'm getting the following error :
    REP 1814 : Report cannot be formatted. Object "vertically" can never fit R_Main (the name of the repeating frame enclosing all objects)
    Thanks,
    Priyanka

    To reduce the Hieght, first make the layout design fit into the new value..

  • Resize and crop images to a specific width and height

    Hi,
    I want to convert images to thumbnails with a 'standard' format - I need all images to have the same width and height.
    So I need to resize and then crop the images. Is this possibe with JAI? Are there other libraries which can do this better?
    I've read about ImageMagick - are the Java interfaces to ImageMagick good?
    /best regards, Håkan Jacobsson - System developer in Sweden

    Duplicate posting, answers are here
    http://forums.sun.com/thread.jspa?threadID=5419291
    Pleas don't duplicate unless you note that you have done so and provide pointers to the duplicates - as I'm sure you're aware. . .

Maybe you are looking for

  • For loops and dynamic sql string syntax

    Hi is there a why to loop through a dynamic sql string normally you would have FOR cur IN (select * from emp) LOOP but I have a dynamic sql string called l_sql I have tried the following FOR cur IN l_sql LOOP but I get PLS-00456: item 'L_SQL' is not

  • How to share structure with arrays in a single file between C# and C with arrays?

    It is possible to define things so that a file that contains a struct definition can be included in both C# and C programs once the differences are taken into account. Most of these differences can be handled but not all. One of those problems is arr

  • Late 2013 15" Macbook freezing, but mouse still responsive, any suggestions?

    Hi, I have a new late 2013 Macbook Pro 15" Retina that keeps freezing periodically throughout the day, When it freezes the mouse can still be moved, but nothing else can be clicked on the keyboard commands are non responsive. I did notice a GPU hang

  • Installed XP Pro - now will not shut down

    I have a PC using an MS-6534 Motherboard that WAS running Windows 98SE with no problems. For 'corporate' reasons the PC has been re-installed with XP Pro. Ever since XP was put on it the PC will not shutdown. It gets to "Windows is shutting down" and

  • Safari does not open anymore.

    Error message: Safari was closed while using Plugins ZZafari. No such plugin in the respective folder. Can't reach the Safari settings as browser closes daown immediately. What can I do?