Paint Component using scaled Graphics with TiledImage

Hello,
I am in the process of adding minor image manipulation in an application I created. I have paint overridden on the component that displays the image and in that component I am scaling the graphics to a representation of the image at 300 dpi versus the screen resolution. The image is a TiledImage which gave me pretty good performance benefits when I was painting at screen resolution. Now I want to know if there is something I can do to the tiles to get the performance benefit back. I understand this
may not be possible because the entire image displays at once with the scaled graphics instance.
Here is a copy of my paint method:
public void paintComponent(Graphics gc) {
          Graphics2D g = (Graphics2D) gc;
          g.scale(scale, scale);
          Rectangle rect = this.getBounds();
          rect.width *= (1/scale);
          rect.height *= (1/scale);
          if ((viewerWidth != rect.width) || (viewerHeight != rect.height)) {
               viewerWidth = rect.width;
               viewerHeight = rect.height;
          setDoubleBuffered(false);
          g.setColor(Color.BLACK);
          g.fillRect(0, 0, viewerWidth, viewerHeight);
          if (displayImage == null)     return;
          int ti = 0, tj = 0;
          Rectangle bounds = new Rectangle(0, 0, rect.width, rect.height);
          bounds.translate(-panX, -panY);
          int leftIndex = displayImage.XToTileX(bounds.x);
          if (leftIndex < ImageManip.getMinTileIndexX())
               leftIndex = ImageManip.getMinTileIndexX();
          if (leftIndex > ImageManip.getMaxTileIndexX())
               leftIndex = ImageManip.getMaxTileIndexX();
          int rightIndex = displayImage.XToTileX(bounds.x + bounds.width - 1);
          if (rightIndex < ImageManip.getMinTileIndexX())
               rightIndex = ImageManip.getMinTileIndexX();
          if (rightIndex > ImageManip.getMaxTileIndexX())
               rightIndex = ImageManip.getMaxTileIndexX();
          int topIndex = displayImage.YToTileY(bounds.y);
          if (topIndex < ImageManip.getMinTileIndexY())
               topIndex = ImageManip.getMinTileIndexY();
          if (topIndex > ImageManip.getMaxTileIndexY())
               topIndex = ImageManip.getMaxTileIndexY();
          int bottomIndex = displayImage.YToTileY(bounds.y + bounds.height - 1);
          if (bottomIndex < ImageManip.getMinTileIndexY())
               bottomIndex = ImageManip.getMinTileIndexY();
          if (bottomIndex > ImageManip.getMaxTileIndexY())
               bottomIndex = ImageManip.getMaxTileIndexY();
          for (tj = topIndex; tj <= bottomIndex; tj++) {
               for (ti = leftIndex; ti <= rightIndex; ti++) {
                    Raster tile = displayImage.getTile(ti, tj);
                    DataBuffer dataBuffer = tile.getDataBuffer();
                    WritableRaster wr = Raster.createWritableRaster(sampleModel,
                              dataBuffer, new Point(0, 0));
                    BufferedImage bi = new BufferedImage(colorModel, wr,
                              colorModel.isAlphaPremultiplied(), null);
                    if (bi == null) continue;
                    int xInTile = displayImage.tileXToX(ti);
                    int yInTile = displayImage.tileYToY(tj);
                    atx = AffineTransform.getTranslateInstance(
                              xInTile + panX, yInTile + panY);
                    g.drawRenderedImage(bi, atx);
          imageDrawn = true;
          if (cropOn) {
               Rectangle cropRect = getDimensions();
               if (cropRect == null) return;
               g.setColor(Color.BLACK);
               g.drawRect(cropRect.x, cropRect.y, cropRect.width, cropRect.height);
               g.setComposite(makeComposite(0.5f));
               g.fillRect(0, 0, cropRect.x, cropRect.y);
               g.fillRect(cropRect.x, 0, viewerWidth - cropRect.x, cropRect.y);
               g.fillRect(0, cropRect.y, cropRect.x, viewerHeight - cropRect.y);
               g.fillRect(cropRect.x + cropRect.width, cropRect.y,
                         viewerWidth - cropRect.x, viewerHeight - cropRect.y);
               g.fillRect(cropRect.x, cropRect.y + cropRect.height, cropRect.width,
                         viewerHeight - cropRect.y);
          g.dispose();
          if (((double)GarbageCollection.getFreeMem() /
                    (double)GarbageCollection.getRuntimeMem()) > 0.7d) {
               System.out.println("Memory Usage: " +
                         (int)(((double)GarbageCollection.getFreeMem() /
                         (double)GarbageCollection.getRuntimeMem()) * 100) + "%");
               System.out.println("Requesting garbage collection.");
               GarbageCollection.runGc();
          setDoubleBuffered(true);
Thank you in advance for support

I moved the sizing out of the paint method and put in a component listener. I am still getting approx. the
same performance. Possibly because I am trying to do too much. I have a mouse listener that allows
the user to pan the image. I also have crop, rotate, shear, and flip methods. The main problem I think
is when I change graphics to scale at (72d / 300d) which puts the display comparable to 300 dpi.
My main reason for this was to allow zooming for the user. Am I overtasking the graphics object by
doing this?

Similar Messages

  • Can't use onboard graphics with graphics card on Z77A-G45 board

    so i got a reman board all works great i have intel core I7 3770  that has built in intel hd 4000 graphics i would like to use it as a third monitor but i go to install the driver it tells me this computer does not meet the min requirements to install this driver um it does ? how do i do it so i can use both monitors? how can i get it to install driver please, i have win 8.1 64 bit any help appreciated.

    Quote from: Svet on 29-January-15, 21:34:50
    try turn off multi monitor and see if it will become detected
    else attach monitor to intel GPU and take out the discrete card and see if that would works
    It worked i had to detach my card then install the driver and go in the Bios like you said and turn off then back on and all is well thank you so much sir

  • Visio Drawing Using Data Graphics with data that has a field that contains Multiple Values.

    I am working on creating a drawing for SMTP connectors.  I decided I would use a Data Graphic connecting to a spreadsheet.  In the spreadsheet there are a few fields that are Multi-Value fields.  For instance SmartHosts contains multiple Ip
    address.  I am trying to get this to format things so that the IPs show on the next line down instead of continuing on the same line until it wraps. 
    Does anyone know a way I could do this?
    Jeff C

    Hi Jeff,
    Arrange the IP values in spreadsheet using Alt+Enter (Use this key pair as a separator between two IP values). Now link this spread sheet to Visio. The values should appear in the same manner in data graphics as your expectation.
    Let me know if you meant something else.
    Thanks,
    Dheeraj 

  • Business Graphics with Web Dynpro?

    Hello @ all,
    I have got a question about displaying dashboards and other charts on mobile devices using SAP Technology.
    1) Does someone know, when it will become possible to display BusinessGraphics in Mobile Devices like BlackBerry, Pocket PC a.s.o buildt with Web Dynpro?
    2) Which Technology can I use instead of Web Dynpro? Does it make sense to use HTMLB or should we use non SAP Products like "JFree Chart" for J2EE applications specially buildt for Mobile Devices?
    Thank you for any hints!
    Mehmet

    Hi Memhet!
    You can use Business Graphics with Web Dynpro with version NWDS 2.0(we are in was 6.40)and could be displayed on mobile devices.We use Symbol devices.I am not sure abt Blackberry.Is that your question? OR Are you looking for some alternate solution to WebDynpro.Is that because you have some limitations in running your WD applications in mobile devices?Just trying to understand......
    Thx
    Gisk
    Message was edited by: Sivakumar Ganesan(Gisk)
    Message was edited by: Sivakumar Ganesan(Gisk)
    Message was edited by: Sivakumar Ganesan(Gisk)

  • Problems with drawRect and drawLine in connjunction with using scaling

    Hi,
    we have trouble with drawing rects and lines when using scaling. Using Java 1.6 Update 6 results in a different drawing than using 1.6_11. Lines and rects are sonetimes shifted one pixel with 1.6_11 while everything is ok using 1.6_06.
    public void paint(Graphics g) // paint method of a subclass of Canvas
       ((Graphics2D)g).scale (0.99, 0.99);
       g.setColor(Color.black);
       for (int i=30; i<900; i+=31)
       g.drawRect (10, i, 150, 21);
       g.drawLine (10, i, 160, i);
    }If scaling is deactivated, then the lines and rects are correctly positioned.
    Any idea? Thank you very much in advance.

    Hi Les,
    Thank you! Yes, you are right. I have just found that topic you mean at [http://forums.sun.com/thread.jspa?forumID=20&threadID=5409536|http://forums.sun.com/thread.jspa?forumID=20&threadID=5409536]. Unfortunately the answer there is a little bit frustrating ;-(
    I wonder why such a fundamental functionality does not work correctly for so many updates of Java. We are involved in engineering charting software and in this area it is strongly recommended to have exact diagrams. Otherwise the general appearance suffers too much.
    What would be the best way to proceed? Send a report to Sun's bug database?

  • How to fill polygon without using paint component ?

    hello,
    i have a class called "public class Arrow2DRhombus implements Shape" with the following constructor:
    public Arrow2DRhombus(Point2D begin, Point2D end) {
            this.x1 = begin.getX();
            this.y1 = begin.getY();
            this.x2 = end.getX();
            this.y2 = end.getY();
            this.initArrow();the code for .initArrow():
    private void initArrow(){
            int length = (int) Math.sqrt(Math.pow(Math.abs(x1-x2),2) +
                           Math.pow(Math.abs(y1-y2),2));
            length=length-19;
    Polygon poly = new Polygon();
            poly.addPoint((int) x1,(int) y1);
            poly.addPoint((int) x1+ length,(int) y1);
              poly.addPoint((int) x1+ length+10,(int) y1+5);
              poly.addPoint((int) x1+ length+20,(int) y1);
              poly.addPoint((int) x1+ length+10,(int) y1-5);
              poly.addPoint((int) x1+ length,(int) y1);
            double rad = this.calcAngle((float) this.x1,(float) this.y1,(float) this.x2,(float) this.y2);
            AffineTransform tx = AffineTransform.getRotateInstance(rad,x1,y1);
            this.arrow = tx.createTransformedShape((Shape)poly);
        }is there a way i can fill the polygon "poly" with the code above .
    i know that i can fill a polygon using when using paintcomponent(Graphics g)
    but here how can i do it.
    10x

    I don't really understand the question. "Filling" a shape implies (to me) that you have a Graphics Object and are doing custom painting. So you would do this:
    a) in the paintComponent() method of a component
    b) in the paintIcon method of an Icon
    c) by painting onto a BufferedImage
    I'm sure there are other ways, but I don't think you just "fill" a Shape object.

  • Can I use a graphics tablet such as Wacom with Keynote?

    I would like to be able to use my Graphics tablet with Keynote to write on my slides while teaching. I am able to use the pen tablet with Powerpoint, I just select pen for pointer and pen color. How do I do this in Keynote?
    Thanks for your help,
    Jackk

    I don't think you can do that within Keynote itself. Is there anything useful in the Inkwell preferences? I have never used a tablet with a Mac before, but I think that Inkwell would have some kind of annotation feature.

  • I'm using Adobe Acrobat with the hope of editing a url on the graphic...a simple 3-letter change, save, close and send for printing..how do I get in edit mode to delete 3 letters and insert 3 new letters?

    ?I'm using Adobe Acrobat with the hope of editing a url on the graphic...a simple 3-letter change, save, close and send for printing..how do I get in edit mode to delete 3 letters and insert 3 new letters?

    pkg4ibm wrote:
    editing a url on the graphic...
    Not sure what you mean by that: is that URL in an image, or is it actual text?
    If it is in an image, then you need to extract the image, edit it with something like Photoshop, then add it back to the PDF.
    If the URL is actual text, I suggest that you remove the entire URL, then add the corrected link.

  • HT1454 Is it possible to play games and using apps using Component or Composite  cables with ipod touch 4g?

    Is it possible to play games and using apps on TV using Component or Composite cables with ipod touch 4g?
    Or using universal dock?
    Or this is only for video?

    The iPod only displays TV out for apps that support TV out. The App description will say if it supports TV out.

  • W500: using the switchable graphics with vista ultimate without the power manager software?

    seriously, invest in a new hitachi travelstar 320gb for 49 bucks from that tiger place online and a usb hard drive caddy, pop in your free clonezilla cd and your rescue and recovery problems will be over!
    after reading all the problems with that software i figured my data was too valuble to get caught in that mess so for under 75 bucks problem solved and i rid my w500 of that bloatware. even cheaper then ordering the recovery disks from lenovo.
    working on getting rid of the rest of the useless software now.
    hey question, how do you use the switchable graphics on the w500 with vista ultimate without the power manager software? if you can thats next!!
    Moderator note: Question added to subject line for clarity.
    Message Edited by Agotthelf on 28-04-2009 08:45 AM

    That's because you are asking a T500/W500 question in the Thinkvantage forum. Anyway, the answer to your question is in this thread.
    ATI recently started packaging their switchable graphics driver together with their regular Catalyst. So downloading their latest driver Catalyst 9.4 from the ATI/AMD site and then modifying it with the Mobility Modder will allow you to use switchable graphics without the power manager. The little problem is just that the released version of the Mobility Modder stopped working with Catalyst 9.2 and you are on your own getting a modified Modder  working on 9.4, see here.
    So I decided not to make more work for myself staying on a modded Catalyst 9.1 and for the time being living without switchable graphics.
    T500: Vista 32, 2.8GHz, 4GB RAM, 15.4" 1680x1050, 500GB 7200rpm, ATI Radeon HD3650 + Intel 4500MHD. T42: XP, 1.7GHz, 2GB RAM, 14.1" 1024x768, 250GB PATA, ATI Radeon 7500.

  • [pavilion g7-2116sr] How can I use amd driver with only integrated graphic?

     Radeon hd 7670m is disabled coz it's broken. Amd driver don't work. Windows use vgasave driver. How can i use amd driver with radeon hd7660g?
    P.S.  Sorry, my english isn't good(

    Hi @Leys 
    I see you are stilll unsuccessful installing the drivers as you get the blue screen.
    Here is a link to Computer Does not Start (Windows 7, Vista, XP) that may help.
    Here is a link to Testing for Hardware Failures (Windows 7, Vista) to determine if your graphic card is defective.
    If the graphic card fails, here is a link to the HP Pavilion g7 Notebook PC Maintenance and Service Guide. Please note page 9 or chapter 1 page 9 for a list of recommended replacement graphic cards.
    If the graphic card passes you may wish to consider doing a restore back to a known good time or a full recovery back to factory.
    Using Microsoft System Restore (Windows 7)
    Performing an HP system recovery (Windows 7)
    During the recovery process there is an option to backup your personal files to prevent data loss.  If you have not done one yet I suggest you do one now.
    Restoring Files that were Backed Up Using HP Recovery Manager (Windows 7)
    At any time you may wish to contact HP support for assistance.
    Please call our technical support at 800 474 6836. If you live outside the US/Canada Region, please click the link below to get a support number for your region.
    World Wide Phone Support
    Good Luck!
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

  • Can I use a graphics tablet with a iPad

    Can I use a graphics tablet with iPad if I have an adaptor

    Because its not supported by iOS or the Bluetooth profiles.

  • Use of graphics card with core install

    Hi,
    We have a sun sparc server that has the solaris core installation. We run our Jrun application server on this machine. We would like to use a mapping software called Mapxtreme that needs a graphics card on the server. Can I use a graphics card without upgrading the core Solaris OS installation.
    Thanks,
    Sreeni

    Well first the limit for the device is 1GB SD Card.
    You can store music, videos, pictures, documents (word files, books and pdf files to name a few) and programs.
    Message Edited by IrreducibleM31 on 03-13-2009 08:19 PM

  • Paint component scope issues

    hi i have 2 classes one is my main and the other is the paint class with void paintcomponent() inside
    how do i pass the x variable inside main class so i can use it inside the Map class
    i know you can use scope e.g. Map map = new Map(x,y); but then i have to use a constructor with
    its own repaint(); method inside but it does not work.
    i was thinking of overloading a constructor aswell so inside one constructor is nothing and in the other with the (x, y) has
    the repaint method inside but that doesn't work either.
    main class
    public class Main
    public static void main(String[] args) {
    MainFrame frame = new MainFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setVisible(true);
    class MainFrame extends JFrame
    private int x;
    private int y;
    // map class with paint component
    Map map = new Map(x,y);
    public MainFrame(){
    this.add(map);
    }paint class
    public class Map extends JPanel {
    private int x;
    private int y;
    public Map(){}
    public Map(int x, int y){
    this.x = x;
    this.y = y;
    repaint();
        @Override
        public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }this does not work, any ideas?
    Edited by: nicchick on Nov 25, 2008 1:00 AM

    um that wasnt exactly what i was looking for i have a better example
    what im trying to do is pass/scope private varibles from the main class to the map class
    but since you use repaint(); to call the paintcomponent override method theres no way to scope varibles like
    x and y to panel?
    this example shows what im trying to do with a mouselistener
    main
    public class Main
    public static void main(String[] args) {
    MainFrame frame = new MainFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setVisible(true);
    class MainFrame extends JFrame
    private int x;
    private int y;
    // map class with paint component
    Map map = new Map();
    // handler
    HandlerMotion handler = new HandlerMotion();
    public MainFrame(){
    this.add(map);
    map.addMouseMotionListener(handler);
         private class HandlerMotion implements MouseMotionListener
            public void mouseDragged(MouseEvent e) {
            public void mouseMoved(MouseEvent e) {
            x = e.getX();
            y = e.getY();
            new Map(x,y);
            repaint();
    }map
    public class Map extends JPanel {
        private int x;
        private int y;
        public Map(){}
        public Map(int x, int y)
        this.x = x;
        this.y = y;
        System.out.println("this is map" + x);
        System.out.println("this is map" + y);
        repaint();
        @Override
        public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawLine(0, 0, x, y);
        System.out.println("this is panel" + x);
        System.out.println("this is panel" + y);
    }

  • Image scaling problem with object handles

    Hi,
    I am facing scaling problem.I am using custom actionscript component called editImage.EditImage consists imageHolder a flexsprite which holds
    image.Edit Image component is uing object handles to resize the image.I am applying mask to the base image which is loaded into imageholder.
    My requirement is when I scale the editImage only the mask image should be scaled not the base image.To achieve this I am using Invert matix .With this
    the base image is not scaled but it  is zoomed to its original size.But the base image should not zoomed and it should fit to the imageholder size always. When I scale the editImage only the mask image should scale.How to solve this.Please help .
    With thanks,
    Srinivas

    Hi Viki,
    I am scaling the mask image which is attached to imageHolder.When i  scale
    the image both the images are scaled.
    If u have time to find the below link:
    http://fainducomponents.s3.amazonaws.com/EditImageExample03.html
    u work with this component by masking the editImage.If u find any solution
    for scale only mask ,plz share the same.
    thanks,
    Srinivas

Maybe you are looking for