Results 1 to 10 of 10
  1. #1
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Unhappy increase pixel size

    Hi,
    Im writing a program that will magnify diagrams (simplified version of the windows magnifier). If I have a buffered image (hard-coded) bufimag, what are the steps to do to increase pixelsize and display it.
    Well displaying is not a problem. just how to increase pixel size. No need to use reg as in getRGB and setRGB.

    Please reply.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    how to increase pixel size
    I don't think you can change the size of a pixel without changing the monitor you are using. It's size is defined by the hardware.
    What are you trying to do? Are you trying to change the scaling of an image? Look at the Graphics class draw methods. They have args you can set to control scaling.

  3. #3
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    Its like the windows magnifier. Or, like the zoom function in MS Paint, increase pixel size of an image. I am trying getpixel and setpixel, but I have manipulate with RGB, which I am not required to do.

    I hardcode a blackand white drawings and want to zoom it. Just a tip would do. Ive spent 2 days on this actually simple program.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default

    Look at BufferedImage#getSubimage and Image#getScaledInstance. Or you could use the Graphics#drawImage method which takes a width and height to magnify the subimage.

    db

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    increase pixel size
    Does this mean you want to change the number of pixels in an image? For example change a 800x600 to 1600x1200.
    Look at the Graphics class draw methods. They have args you can set to control scaling.

  6. #6
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    Thanks.
    Let me try the getscalinstance method. the drawimage method doesnt seem to work.
    Thanks.

  7. #7
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Post

    For some reason, it doesnt work. If I were to code it to fill the screen with a color, when I click magnify; it fills it. but does not magnify.

    This is the snippet of my code just for the magnify method:
    Java Code:
      public void magnifyme()
      {
          int height,width=0;
          int pixel;
          bufImag = new BufferedImage(offScrWidth,offScrHeight,BufferedImage.TYPE_INT_RGB);
          if (bufImag == null)
          {
            System.out.println("MyPanel constructor: ERROR - couldn't get memory for BufferedImage");
            return;
          }
    
          g2 = bufImagThin.createGraphics();
    
        setPreferredSize(new Dimension(offScrWidth*5,offScrHeight*5));
    
        g2.setColor(Color.white);
        g2.fill(new Rectangle(0,0,offScrWidth*5,offScrHeight*5));
    
        height =bufImagThin.getHeight()*5;
        
        width = bufImagThin.getWidth()*5;
       
         g2.drawImage(bufImagThin,0,0,width,height,null);
      }
    or

    Java Code:
      public void magnifyme()
      {
          int height,width=0;
          int pixel;
          bufImag = new BufferedImage(offScrWidth,offScrHeight,BufferedImage.TYPE_INT_RGB);
          if (bufImag == null)
          {
            System.out.println("MyPanel constructor: ERROR - couldn't get memory for BufferedImage");
            return;
          }
    
          g2 = bufImagThin.createGraphics();
    
        setPreferredSize(new Dimension(offScrWidth*5,offScrHeight*5));
    
        g2.setColor(Color.white);
        g2.fill(new Rectangle(0,0,offScrWidth*5,offScrHeight*5));
        height =bufImagThin.getHeight()*5;
    
        width = bufImagThin.getWidth()*5;
     
        Image scaledImag = bufImagThin.getScaledInstance(width, height, Image.SCALE_FAST);
        g2.drawImage(scaledImag, 0, 0, null);
      }
    The fault is only in this function, if I remove this function, the rest of the program works.
    Please suggest what could be the fault.
    Last edited by rosh72851; 10-01-2008 at 07:11 PM.

  8. #8
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    never mind. I put a repaint command before magnify.
    The program works now.
    Thanks again guys.

  9. #9
    DrMadolite is offline Member
    Join Date
    Jul 2012
    Location
    Norway
    Posts
    29
    Rep Power
    0

    Default Re: increase pixel size

    I was asking the same question recently. Nice to see some good answers.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default Re: increase pixel size

    That's all very well, but in future don't bump ancient threads to the top of the forum listing.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. Replies: 3
    Last Post: 09-27-2008, 04:46 AM
  3. How 2d Pixel Arrary Is Stored In .txt/.dat File
    By Mazharul in forum New To Java
    Replies: 1
    Last Post: 08-18-2008, 12:23 PM
  4. gridbaglayout: increase/decrease size of components.
    By newtojava7 in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 07:22 AM
  5. Replies: 1
    Last Post: 07-17-2007, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •