Drawing parts of Images

Hi,
Is there a way to draw only part of a BufferedImage (or any Image) to a Graphics object using the standard AWT tools?
Specifically, my problem is that I'm using a single large background image in my game (which I can't break into seperate files beforehand). When a mouse motion occurs, I redraw this to my buffer, redraw everything over it, and then repaint.
Unfortunately, it takes so long to redraw the image to the buffer that skips are occuring in the motion (I've checked, and the "redraw everything" part is actually okay-- it really is the drawImage method where things start to hang up).
I can easily identify the region of the screen that needs to be redrawn. What I'd like to do is to redraw only that 'piece' of the background image, and leave the rest of the buffer alone.
Is there any way to do this? Any alternatives or other issues I should consider?
Thanks,
Steve C.

yes, if you look into the various graphics.drawImage signatures, you'll see that you can crop out part of an image to draw right there. You may also look into how to use VolatileImage, as it is designed to hardware accelerate images that are not changed often (such as backgrounds in games)

Similar Messages

  • Trouble drawing on saved images in whiteboard, please help!

    I use the Image.IO.write(image,"png",file) method to save my whiteboard drawings onto a file and it displays fine when I import it. But when I draw on it it seems some of my whiteboard buttons are "blending in" with the drawing area where the image is. I guess a way to imagine is there is a row of buttons then a panel containing the image. When I draw on the image area the image of the bottons above are mixed in and everything looks bad. Any idea what I am doing wrong in saving the image? thanks!

    Yes, I see the big ugly squares. They are what appears whenever extremely heavy JPEG compression is applied to a low-resolution image tht has relatively large areas of similar colors. Something somewhere is applying such compression to the pages, or portions of them, that you are viewing in your browser(s). Your MBP is not doing that: it can't. Either the page images (or parts of them) are being compressed by the website owners or, if every web page is affected, they are being compressed by your ISP in the process of being transmitted to you, as Gordito suggests. That would greatly increase the speed of page loading, but at the expense of image quality. You wouldn't see the image degradation on an iPhone or cell phone — the screen is too small — but on the MBP's high-resolution display it would be much more apparent, IF the MBP were receiving the signal in the same highly compressed form as the phone. If the MBP receives the same web pages through an ISP that doesn't over-compress them, they'll look the way they ought to look. So if you are receiving these web pages through a cellular ISP rather than through a broadband connection, take the MBP to a wifi hotspot and connect through wifi instead. I bet things will look different then.
    Compressing images is something a web browser can't do: a browser just displays the signal that comes to it.

  • Changing fill colour for partly transparent images

    Does anyone know how to change the fill colour used for partly transparent images? I have a bunch of PNGs that I made for use as clip art, which I imported into iPhoto (that way I can use the media browser with Pages and Keynote).
    Unfortunately, the images (which are black) are shown on top of a black rectangle both in iPhoto and the media browser. I've tried changing the background colour to both gray and black, but the 'fill' colour stays black.

    There's no way to change it if you want to keep the transparency for use in other applications or web pages.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.

  • Drawing moving GIF images?

    Is it possible to draw moving gif images on a simple Frame applet?
    I made an image drawer class for my applet and i can draw simple 2d images.
    Here is the basis of my GameSprite class;
        public byte[] pixels;
        public int width;
        public int height;
        public GameSprite(String imageName, int requestIndex) {
         try {
                    // Removed code, it's zipInputStream, but it can be used just as ./image.jpg etc
         javax.swing.ImageIcon icon = new javax.swing.ImageIcon(fileBytes);
         width = icon.getIconWidth();
                     height = icon.getIconHeight();
                     pixels = fileBytes;
         } catch(Exception e) {
              e.printStackTrace();
        public void drawSprite(int x, int y) {
         try {
              Image image = Toolkit.getDefaultToolkit().createImage(pixels);
                                    //Removed code here
              graphics.drawImage(image, x, y + 7, width, height, observer);
         } catch(Exception e) {
              e.printStackTrace();
        }If i try to draw an animated gif image it dosn't move.
    Thanks for any help.

    In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
    If you where overriding a Panel in AWT you would override paint:
    public void paint(Graphics g){
      g.drawImage(im, 0, 0, this);
    }Then where you are maipulating your graphics you would do something like this:
    //code snippet
    Graphics g = im.getGraphics();
    //make what ever changes to im by manipulating the graphics context g
    repaint();

  • How convert a big image to parts of images? means split a jpg image to several sub imges.(thi​s sub image can joint into that big image)

    hi friends..
    how convert a big image to parts of images? means split a jpg image to several sub imges.(this sub images can joint into that big image) any help
    Solved!
    Go to Solution.

    In the example, i have created two images and added them together, and the converse can be done in the same way.
    Thanks
    uday,
    Please Mark the solution as accepted if your problem is solved and help author by clicking on kudoes
    Certified LabVIEW Associate Developer (CLAD) Using LV13

  • Why can't I draw over imported images?

    If someone could explain to me (in simple terms-I've only been using flash since friday and I don't know the names ofthings properly yet) why I can't draw over impoted images? I've animated something on paper and scanned in the frames. When I import them to flash it either deletes the line as soon as I draw it, or if I create a new layer the drawing stays in all frames, not just one. Pllllllease help, I'm desperate!

    When you create a new layer, you can use keyframes to display the image in just one frame. Add a keyframe just after the frame where the image should not be displayed. So rightclick in that frame, and click add keyframe. Then in the new keyframe you can remove the image.
    I believe you can use Flash to convert bitmap images to vector images, but I haven't used that function since Flash 2, so I don't know if that still exists. The result might be useless though if the images is too complex. But if it's okay, then you can edit the image itself. Otherwise draw on a layer on top of the image.

  • Save Part of Image

    I have a question here. Now, I have a scanned picture and if I were to save the whole picture, it is a was of disk place. Can I save only part of the picture? If yes, can I know where can I get the guides or samples regarding this.
    Thank you.

    use CropImageFilter Crop the part of Image
    and then ... ...

  • I want a rectangular frame round part of image to draw attention to it?

    I am making a clip to demonstrate my camera zoom by starting off at W/A and zooming in.
    I want to highlight the area I am going to be zooming to by drawing a frame around it.
    The only rectangles and circles I can find in the Generators appear to be solid shapes or solid shapes with a border.
    There doesn't appear to be any way of getting rid of the central colour so the underlying video will show through.
    Any ideas.
    I could do it in FCP 7 but if possible I would like to use FCP X.

    I must be blind!
    I have just spotted the Fill tick box!
    I was looking for it before I posted but could only see the Outline tick box!
    Send a brief reply and you can have the rest of the points.

  • Error #2123 bitmap.draw à partir d'un flux HDS dans une application Flex

    Bonjour à tous,
    Je suis en train de développer un player vidéo en Flex qui doit prendre en charge le HDS.
    J'essaie en vain depuis hier de créer une une image Bitmap à partir d'un flux HDS que je récupère d'Akamai.
    J'ai essayer avec un Flux RTMP, aucun problème, j'arrive bien à créer une image bitmap à partir du flux vidéo. Mais dès  que j'essaie avec un flux HDS, j'ai une erreur # 2123 qui correspond à une violation de sécurité.
    le message complet :
    Error #2123: Violation de la sécurité Sandbox : BitmapData.draw : http://192.168.0.194/test-hds/testHDS.swf ne peut pas accéder à null. Accès refusé à tous les fichiers de régulation.
    J'ai créer un serveur avec Wowza en version trial pour avoir un exemple de flux HDS. Même problème qu'avec le flux d'Akamai
    Mon Code :
    Fichier testHDS.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    minWidth="955" minHeight="800" creationComplete="init()" layout="absolute">
            <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
        <fx:Declarations>
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                import mx.core.FlexGlobals;
                import mx.core.UIComponent;
                private var osmfPlayer:OSMFPlayer;
                public function init():void{         
                    Security.allowDomain("*")
                    Security.loadPolicyFile("http://192.168.0.194/crossdomain.xml");              
                    osmfPlayer = new OSMFPlayer();
                    this.addChild(osmfPlayer);
                protected function myBtn_clickHandler(event:MouseEvent):void
                    try {
                        var dpo:DisplayObject = osmfPlayer.player.displayObject;      
                        var imgBD:BitmapData;
                        var imgBitmap:Bitmap;
                        imgBD = new BitmapData(100,100);
                        imgBD.draw(osmfPlayer.player.displayObject as DisplayObject);
                        imgBitmap=new Bitmap(imgBD);              
                        var comp :UIComponent = new UIComponent();
                        comp.addChild(imgBitmap);
                        comp.x =0  ;
                        comp.y = 720;
                        addChild(comp);
                        Alert.show("ok");              
                    catch(e:Error){
                        Alert.show(e.message);
            ]]>
        </fx:Script>
        <s:Button id="myBtn" x="0" y="720" label="MyButton" click="myBtn_clickHandler(event)">      
        </s:Button>
    </mx:Application>
    Fichier OSMFPlayer.as
    package
        import mx.core.UIComponent;
        import org.osmf.containers.MediaContainer;
        import org.osmf.media.DefaultMediaFactory;
        import org.osmf.media.MediaElement;
        import org.osmf.media.MediaPlayer;
        import org.osmf.media.URLResource;
        public class OSMFPlayer extends UIComponent
            //URI of the media
            public static const PROGRESSIVE_PATH:String =
                "http://192.168.0.194:1935/vod/mp4:sample.mp4/manifest.f4m";       
            public var player:MediaPlayer;
            public var container:MediaContainer;
            public var mediaFactory:DefaultMediaFactory;  
            public function OSMFPlayer()
                initPlayer();
            protected function initPlayer():void
                //the pointer to the media
                var resource:URLResource = new URLResource( PROGRESSIVE_PATH );
                // Create a mediafactory instance
                mediaFactory = new DefaultMediaFactory();      
                //creates and sets the MediaElement (generic) with a resource and path
                var element:MediaElement = mediaFactory.createMediaElement( resource );
                //the simplified api controller for media
                player = new MediaPlayer( element );
                //the container (sprite) for managing display and layout
                container = new MediaContainer();
                container.addMediaElement( element );
                //Fit the player size
                container.width =  1280;
                container.height = 720 ;//- FlexGlobals.topLevelApplication.actionBar.height;
                //Adds the container to the stage
                this.addChild( container );
    crossdomain.xml
    Emplacement :  à la racine du serveur
    <?xml version="1.0"?>
    <cross-domain-policy>
    <site-control permitted-cross-domain-policies="master-only" />
    <allow-access-from domain="*" />
    <allow-access-from domain="*.adobe.com" />
    <allow-access-from domain="*.macromedia.com" />
    </cross-domain-policy>
    //fin de code
    J'ai d'abord pensé que c'était lié au crossdomain.xml, j'en ai testé un certains nombre, ca ne change rien.
    Je ne sais plus trop quoi faire
    Si quelqu'un avait une idée ou une piste, je suis à cours !
    Merci d'avance

    Perhaps if you are going to use a foreign language in your post, you should use it in the title, also, so as otherw will know what to expect... you will be more likely to get responses from those who speak the same language also... not a criticism, just a suggestion. and no need to repost again...

  • How do you magnify part of image in CS5

    In the past, command-space will allow me to zoom in on a specific portion of an image. In CS5, the photo just blows up into an unviewable mess. Tried a search but can't find new shortcut to zoom in/out on a specific portion of an image. Sorry for asking something that I know should be easy. I googled and found that I shoud select zoom tool. Got that part but I can't draw a box around the specific area I want enlarged. Thx.

    Here are the methods I use to zoom in and out:
    - Command + or Command - to zoom in/out incrementally.
    - Hold Option key and use scrollwheel.
    - Use zoom tool (or Command-space) and click and drag around area to enlarge.
    If I need to do a lot of back and forth, I usually open a second window for the document (Window > Arrange > New Window for ...) and keep the windows side-by-side. I zoom in closely in one window to do fine editing and view the result in the second window.

  • Select part of image

    Hi all,
    I�m programming a Swing-GUI with serveral different Panel.
    I want to be able to select an area within a ScollPanel I�m drawing a
    rectangle using MouseListenerEvents and the draw-method, which I
    implemented in an inner class.
    My problem is, that I�m able to draw the rectangle over the whole GUI,
    and not just the one ScrollPanel.
    Does any of you have an idea, what I�m doing wrong? Any hints or
    solutions are
    very much appreciated.
    Thank

    hi
    you can use quick selection tool,select the part of the image you want and then simply create a mask on that layer .
    as you can see in this image i have just selected the rose flower
    and below in the original image

  • Sample program for drawing nodes on image

    Hi guys ,
    Can any of you send me a sample program to do this .
    I should be able to load a image in a applet ,On this image i should be able to draw line like nodes for example to select a part of the image the user requires ,after the selection the user should be able to resize the selected part of the image .
    Any help would be greatly appreciated.
    Thanks you very much in advance
    Chetan

    //  <applet code="DragClip" width="400" height="400"></applet>
    //  use: >appletviewer DragClip.java
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class DragClip extends JApplet {
        public void init() {
            ClipPanel clipPanel = new ClipPanel();
            Clipper clipper = new Clipper(clipPanel);
            clipPanel.addMouseListener(clipper);
            clipPanel.addMouseMotionListener(clipper);
            Container cp = getContentPane();
            cp.add(clipPanel);
    class ClipPanel extends JPanel {
        BufferedImage image;
        Dimension size = new Dimension();
        Rectangle clip = new Rectangle();
        public ClipPanel() {
            loadImage();
            size.setSize(image.getWidth(), image.getHeight());
        public void setClip(Point p1, Point p2) {
            clip.setFrameFromDiagonal(p1, p2);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            int x = (w - size.width)/2;
            int y = (h - size.height)/2;
            g2.drawImage(image, x, y, this);
            g2.setPaint(Color.red);
            g2.draw(clip);
        public Dimension getPreferredSize() { return size; }
        private void loadImage() {
            // Image file located on classpath.
            String path = "images/bison.jpg";
            try {
                URL url = getClass().getResource(path);
                image = ImageIO.read(url);
            } catch(IOException e) {
                System.out.println("Read error: " + e.getMessage());
    class Clipper extends MouseInputAdapter {
        ClipPanel component;
        Point start;
        public Clipper(ClipPanel cp) {
            component = cp;
        public void mousePressed(MouseEvent e) {
            start = e.getPoint();
        public void mouseDragged(MouseEvent e) {
            component.setClip(start, e.getPoint());
    }

  • How can I display the length of the yet unfinished line that a user is drawing in the image using the line tool of the IMAQ tool palette.

    Is this really not possible using standard Labview/Vision YI`s?

    Herbert,
    I can't find a way to extract the information you want within the program. However, this information is displayed as part of the IMAQ tool palette while the user is drawing the line. The pallette shows the anchor point, the X and Y offsets, and the line length and angle.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • Print part of image in CS4?

    I recently upgraded from CS3, and I seem to have lost the ability to print part of an image.
    I'm sure that in CS3, if you tried to print an image that was larger than the paper, you got a warning saying it would be cropped, but you could still move the image in the print preview to get the part you wanted. How do I do this in CS4, without cropping?

    You can still do this in CS4.
    In the Print dialog,  Center Image and Scale to Fit Media must both be unchecked, and Bounding Box must be checked.
    Then you can slide the image around in the preview window as much as you like.
    You can also drag the corners of the bounding box in the preview to manually scale the image.
    Unfortunately, many printers will not print an image that extends past the printable area. If this is the case, you'll be able to go past the warning message, but the page will probably come out blank. If you can set your printer to print bleeds, then you can probably print the portion of the image that falls within the printable area.
    (I was also going to explain how to set a pre-sized selection and then print just the selected area, but the "print selected" checkbox in the print dialog seems to be broken at the moment. So here's a pretty useful work-around that you may need to use if bleeds are a problem.)
    1. Select the Crop tool (C / Shift-C) and enter the width and height of your printer's printable area. You can enter "8.27 in" or "2750 px" etc. If you don't know your printer's official printable area, just allow about 1/4 to 1/2 inch of border (e.g., 8 in x 10.5 in for letter size).
    2. Then, in the settings bar, enter a reasonable pixels per inch for your printer (300 should work fine) in the Resolution field.
    3. Then drag the crop marquee over your image and position or size it as you like. Because the Width and Height are not blank, the crop area will retain the correct proportions. Note that whatever size crop area you create, the crop operation scales that portion of your image to the specified Width and Height.
    4. Then press Enter or Return or click the big checkbox on the settings bar. Don't save your document!
    5. Print the cropped document as usual, and after the print dialog closes, press Ctrl-Z (Command-Z) or choose Edit / Step Backwards to undo the crop.

  • In the Picture control, how can I draw a small image at a specific offset within a larger image?

    I could use the opposite of "Get Image Subset.vi", like a "Set Image Subset.vi".
    The "Draw Flattened Pixmap" function would work if it would let me define the target position instead of the source position.
    Solved!
    Go to Solution.

    You can use "Draw Unflattened Pixmap.vi". Here is an example:
    Marc Dubois
    HaroTek LLC
    www.harotek.com

Maybe you are looking for

  • Why does my Web Handler work with Internet Explorer, but not with Firefox

    I am trying to develop a web page that uses the Simile Timeline (http://code.google.com/p/simile-widgets/wiki/Timeline) with data from SQL Server. In initial testing of my timeline I tested it with Example.xml, a static XML file in the correct format

  • How does apple TV cache content, + use with imac

    I am thinking about buying an apple TV, but have some questions -does the Apple TV only stream content in real time, or can it store content e.g If I want to watch a film with the family, can I download the full film to the apple tv in advance, or do

  • Best program to monitor time spent on FCP, Motion, Soundtrack Pro?

    I run a small company as a free lance doc-film maker and was wondering if anyone could recommend the best program for keeping track of time spent working on Final Cut Pro, Motion, and Soundtrack Pro projects for my clients. I'd like a program that tr

  • CS4 10.6 Canon ipf6100 printer issues: profiles, plug-in, driver

    The relevant hardware and software are listed above plus the most recent photoshop plug-in from Canon. As of two days ago, all was up to date. Although some Canon Tech Support reps (but not others) have been surprised by this, I have been getting goo

  • DBrestore with out controlfile

    hi All, One of our server was crashed .. i has  restored with online backup ... but the thing is i dont have controlfile .... when  iam starting the SQL iam getting this error .... sql>startup "ORACLE instance started. Total System Global Area 101082