Please Help me on Image Scaling!!

I am trying to get a map.jpg to scale to fit the window while still able to zoom in & out with mouselistener(which where I clicked). I am able to zoom in & out but the coordinate is according to the original size. Please help.

1.I am not familiar with Graphics & Graphics2D. The Following code have problem in showing the map in BufferedImage, which is plotted with small dots on it. Actually, it's the Graphics & Graphics2D coding problem that I am facing. I don't know how to use the function.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.awt.image.*;
import java.awt.geom.*;
public class GPSMap extends JPanel
private Image map,scaled;
private double zoomfac=1;
private BufferedImage bufi;
int zoomcx,zoomcy,zoomh,zoomw,w,h,newHeight,newWidth,newx,newy,newcx,newcy;
public GPSMap()
System.out.println("Loading GPSStatus");
this.setLayout(new BorderLayout());
map = getToolkit().getImage("Map3.jpg");
MediaTracker track=new MediaTracker(this);
track.addImage(map,0);
try{track.waitForID(0);}
catch(InterruptedException ie){}
w=map.getWidth(this);
h=map.getHeight(this);
bufi=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB_PRE);
newHeight=650;
newWidth=(int)(newHeight*w/h);
scaled=map.getScaledInstance(newWidth,newHeight,map.SCALE_SMOOTH);
addMouseMotionListener(new MouseMotionAdapter()
public void mouseMoved(MouseEvent m)
     System.out.println("Move at ["+m.getX()+", "+m.getY()+"]");
zoomcx = m.getX()-(zoomw/2);
zoomcy = m.getY()-(zoomh/2);
     newx=(int)(m.getX()*newWidth/w);
     newy=(int)(m.getX()*newHeight/h);
     newcx=newx-(zoomw/2);
     newcy=newy-(zoomh/2);
if (zoomcx <= 0)
zoomcx = 0;
if (zoomcy <= 0)
zoomcy = 0;
// if (zoomfac != 1)
// repaint();
repaint();
The following part is an extra but cannot do it.
addMouseListener(new MouseAdapter()
public void mouseReleased(MouseEvent m)
if (m.getModifiers() == InputEvent.BUTTON3_MASK)
zoomfac = zoomfac - 0.21;
else
zoomfac = zoomfac + 0.21;
     if (zoomfac <=1)
     zoomfac=1;
repaint();
public void paint (Graphics g)
GPS3 s3=new GPS3();
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHints(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED);
Graphics2D gc=bufi.createGraphics();
gc.setColor(Color.red);
for(int i=0;i<=s3.ix.length;i++){
     gc.drawRect(s3.iy[i]-1,s3.ix[i]-1,2,2);//For plotting purposes, but not yet finish
gc.drawImage(scaled,50,50,this);
gc.drawImage(bufi,zoomcx,zoomcy,newcx,newcy,100,70,this);
P.S. I don't know how to change it to runnable application. Please help.

Similar Messages

  • Please help, my Canon Image Formula P-215 will not work w/ Mavericks

    Please help, my canon image formula p-215 will not work w/ the new mavericks upgrade, is there a work around?

    I ran into the same problem, I posted what worked for me in another topic in this forum:
    https://discussions.apple.com/message/25208435#25208435
    Hope it helps

  • Please help : invalid fiasco image header , and %...

    yes i'm getting these 2 messages, i'm just trying to reflash but i can't, please help me, i tried changing the name of the images, adding .bin ( on xp ) ... but i just can't reflash please help me, i tried these on win7 32bits, and on xp sp3, i'm getting the same thing please can someone help me . note : my device shows the nokia logo, usb logo..... without a backlight, they are all dark, please guys help me .
    Reality is wrong....dreams are for real... 2pac .
    don't forget to hit that green kudos
    Solved!
    Go to Solution.

    I've been really busy with work.. really really busy.. hopefully this week might start to get a bit quieter..
    Right..
    %m means "File not found or bad file name"
    when you run "flasher-3.5 -F os.bin -f" flasher wil be looking for a file called os.bin.. If it can't find os.bin, it gives you the error %m
    Why does it say %m and not something clearer? That's because of a bug in Nokia's software!
    Ok.. Did you download the zip file I sent you? If so here's how I think we can do this:
    Step 1) Open a CMD window
    Go to the start menu, select run then type CMD
    A black cmd window will pop up.. in that window run these commands exactly:
    cd %ProgramFiles%\maemo\flasher-3.5
    start .
    A windows explorer window will appear. Move this window out of the way.. BUT don't close it
    Step 2) move the bin files
    Find the zip file you downloaded.. double click to open the file
    Inside you'll find two bin files
    Drag both files from the zip file into the explorer window that popped up in step 1
    Now close the zip file window
    Step 3) rename the bin files
    In the windows explorer window into which you dragged the bin files, you have to rename the files
    Click on
    RX-51_2009SE_10.2010.13-2.VANILLA_PR_EMMC_MR0_ARM
    and rename (press F2) the file to emmc
    Click on RX-51_2009SE_10.2010.19-1.003_PR_COMBINED_003_ARM.bin
    and rename (press F2) the file to os
    Step 4) flash the files
    unplug and turn off your phone
    In the black cmd window run this command
    flasher-3.5 -F os.bin -f
    flasher will pause saying "waiting for suitable device"
    Press and hold the U button on your phone and plug it in via usb.. you can let go of the U button when flasher starts doing something
    Once flasher has finished (it will say "completed successfully") you can continue:
    run this command
    flasher-3.5 -F emmc.bin -f -R
    That should be it

  • Please, Please Help Me (.gif Images)

    Hello,
    I want to cry, I've been trying to include .gif images in my swing applications but am having big problems. I've been reading the forums and trying everything. If I try the most basic of examples just to get it working I still have problems. The code compiles correctly and the panels appear but no pics. I've tried including every different file path version, moving .gifs to different folders, what is the problem, why no pics. I'm running J2SE v 1.4.1_02, please help, I would be so greatful, don't make me cry,
    Lucy
    import java.awt.*;
    import javax.swing.*;
    public class JFrameImage extends JFrame
    public JFrameImage()
    Container c = getContentPane();
    JPanel panel = new JPanel()
    public void paintComponent(Graphics g)
    ImageIcon img = new ImageIcon("globe.gif");
    g.drawImage(img.getImage(), 0, 0, null);
    super.paintComponent(g);
    panel.setOpaque(false);
    ImageIcon icon = new ImageIcon("cat.gif");
    JButton button = new JButton(icon);
    panel.add(button);
    c.add(panel);
    public static void main(String[] args)
    JFrameImage frame = new JFrameImage();
    Image onFrame = Toolkit.getDefaultToolkit().getImage("icon.gif") ;
    frame.setIconImage(onFrame);
    frame.setSize(200,200);
    frame.setLocation(300,200);
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setVisible(true);

    sorry but I think it should be something else.
    To locate a File you need it's full name, including the extension. Maybe since the extension wasn't showing it's actual filename was cat.gif.gif? I don't know. Anyway, this is a method I use for all my image retrieving, just put it in some Util-class:  private static HashMap hmImages = new HashMap();
      public static ImageIcon getImage (String name)
        if (hmImages.containsKey(name))
          return (ImageIcon) hmImages.get(name);
        String url = System.getProperty("user.dir") + "/resources/" + name;//or any other directory were all your image-files are under (even in subs, in that case add the subdirectory to the arg name
        try
          ImageIcon ic = new ImageIcon (url);
          if (ic != null)
            hmImages.put(name, ic);
            return ic;
        catch (Exception e)
        System.out.println("Warning: image '" + url + "' not found");
        return null;
      }greetz,
    Stijn

  • Please help my desktop images, wallpapers gone.

    Please community i need your help. I restored my computer from Lion to lion, before i had Leopard and i had all my favority desktop wallpapers, for example aurora , earth horizon , earth etc..      When i installed for the first time Lion , i got even more desktop images  for ex. Aurora at grey or blue colors those i loved so much . I am so new to mac's ok i did not even know where my folders were, i even wanted to get the same background images for me phone too ^^. But when i did a restore from Lion to Lion means that i erased(and i forgot to backup or search for the desktop images on my mac it was to late ) my disk and got the install all over again , all my desktop wallpapers were gone. Now please if possible for some1 to sent me if he got upgraded from Leopard to Lion and did not erased or kept a backup of desktop images, to simple sent me the folder with all the descibed images i mention, i would be very happy again thank you.

    have had the same problem. also not a computer buff - mine had not been in for work when it would go to sleep after i had shut if down. happened a few times then i lost photos, lots of them. took it to local APPLE repairs and they found nothing, 21 days later.
    last night it did it again - powered off at home and sleeping when i got to the office.
    any advice?

  • Please help, cannot compare images in full screen mode

    I am not able to compare 2 images in full screen mode. I am using a MBP and a ACD 23". The main image will remain in the ACD while the image being compare is being shown in the MBP.
    I am able to compare images in the viewer mode.
    My main display is the ACD 23 which I selected using the display preferences under 'Arrangement' with the menu bar located on the ACD. In Aperture, Secondary Viewer is set to Blank.
    I had also tried different combinations of Main Viewer and Secondary Viewer settings but was not successful.
    Am I missing something? Anyone have the solution?Thanks in advance for any help.
    norheng

    Anyone have any suggestions to using Aperture to edit images using a MBP and ACD so that it best utilize Aperture full screen mode in comparing and narrowing down to the pick.
    I am now trying to use the MBP as the main display and ACD as the secondary. This way I am able to compare images with the MBP in the Browser mode and the ACD display the compare images full screen. It work with the secondary display - ACD set to mirror, span and alternate mode.
    It would be best if only one screen is use and hence save energy consumption (reducing global warming and bill, if it help).
    Thanks in advance for any suggestions or and solutions.
    norheng

  • Please help to load image in the database

    Hi to all. ....
    I need to save image file in the database thru forms ...
    I have some image file in the application server and I need to load it in the database in a Blob col..
    Any help ... ??
    Thank's in advance

    Hi!
    Your forms version is very important.
    If you use forms 10g and you want to load the image on the client, you need webutil.
    If you use forms 6 or you want to load the image from the application server to
    a image item in your form, you can use the read_image_file forms build-in:
    read_image_file ( 'x:\path\image.jpg.', 'JPG', 'block.image_item' );On forms 10g this will be executed on the server and the filename and path has to be
    a physical place on your servers harddisk.
    The image item has to be an item of type image and must be assinged to a blob colum in your table.
    Regards

  • Please Help!! Images for Contacts

    How do I go about getting the contact images to display on my ipod? I have set all images in my Address book, but they don't come over when I sync my contacts. How do I get the images of each individual contact to display in my contacts???

    You need to upgrade to Mac OSX 10.4.3 in order to get photos for contacts.
    http://docs.info.apple.com/article.html?artnum=302493

  • Image scaling problem

    Hello,
    I have been trying to scale an image to create a thumbnail. The thumbnail image size is around 200*200. The thumbnail is to be rendered on a web browser. My code is:
    public static byte[] getScaledImage(InputStream imageData) throws IOException {
           Image origImg = ImageIO.read(imageData);
           int origImgHeight = origImg.getHeight(null);
           int origImgWidth = origImg.getWidth(null);
           int newImgHeight /*determined by custom logic*/;
           int newImgWidth /*determined by custom logic*/;
          /* code for determining newImgHeight and newImgWidth  keeping the aspect ratio */
           origImg = origImg.getScaledInstance(newImgWidth, newImgHeight,
                                               Image.SCALE_AREA_AVERAGING);
           BufferedImage bimage = null;
           bimage = new BufferedImage(origImg.getWidth(null), origImg.getHeight(null),
                                      BufferedImage.TYPE_INT_RGB);
           Graphics g = bimage.createGraphics();
           g.drawImage(origImg, 0, 0, null);
           g.dispose();
           ByteArrayOutputStream os = new ByteArrayOutputStream(10);
           ImageIO.write(bimage, "jpg", os);
           return os.toByteArray();
    }The calling method is:
    FileCopyUtils.copy(ImageUtils.getScaledImage(lobHandler.getBlobAsBinaryStream(rs, 1)),
                                          imageContent);here imageContent is the http response's outputstream.
    Now the problem is the resulting image displayed on the web page becomes distorted. I first thought that this is due to the thumbnail size. But the scaling done by gimp does not distort the image.
    I have also tried this:
    BufferedImage thumbImage = new BufferedImage(newImgWidth, newImgHeight, BufferedImage.TYPE_INT_RGB);
           Graphics2D graphics2D = thumbImage.createGraphics();
           graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
           graphics2D.drawImage(origImg, 0, 0, newImgWidth, newImgHeight, null);instead of using getScaled instance.
    What could be the problem? This is a problem I need to solve immediately. So I am at a loss. Please help me here.

    Try scaling your source image like this:
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ScalingToSize {
        int W = 200;
        int H = 200;
        int SCALE_TO_FIT  = 0;
        int SCALE_TO_FILL = 1;
        private JPanel getContent(BufferedImage image) {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weightx = 1.0;
            panel.add(wrap(image), gbc);
            panel.add(wrap(scale(image, SCALE_TO_FIT)), gbc);
            panel.add(wrap(scale(image, SCALE_TO_FILL)), gbc);
            return panel;
        private BufferedImage scale(BufferedImage src, int style) {
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage dest = new BufferedImage(W, H, type);
            Graphics2D g2 = dest.createGraphics();
            if(style == SCALE_TO_FIT) {
                g2.setBackground(UIManager.getColor("Panel.background"));
                g2.clearRect(0,0,W,H);
            double scale = getScale(src, style);
            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 dest;
        private double getScale(BufferedImage image, int style) {
            double xScale = (double)W/image.getWidth();
            double yScale = (double)H/image.getHeight();
            return (style == SCALE_TO_FIT) ? Math.min(xScale, yScale)
                                           : Math.max(xScale, yScale);
        private JLabel wrap(BufferedImage image) {
            ImageIcon icon = new ImageIcon(image);
            return new JLabel(icon, JLabel.CENTER);
        public static void main(String[] args) throws IOException {
            String path = "images/cougar.jpg";
            BufferedImage image = ImageIO.read(new File(path));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new ScalingToSize().getContent(image));
            f.pack();
            f.setVisible(true);
    }

  • HELP...images not showing up in internet explorer, but show up in Safari

    Somebody please help. My images are showing up fine in Safari
    but when I view them with internet explorer they show an x and
    won't open. I am using layers and tables. Please help!
    Here is my webpage if you need to see code.
    http://www.puddlefoot.com/Tees.html
    Thanks!

    Yonion.jpg is in CMYK colorspace, that's why it doesn't
    display in most
    browsers.
    make it an optimized RGB jpeg file.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • Please Help! I need to have fixed .jpg sizes within scaled .swfs - AS1 - Elearning Flash

    Hello,
    I'm new to this forum by 2 min. and I  have been using Flash for a while, but I'm now working at a place that has brought up issues while using images in our E-learning Flash Projects.
    The Problem:
    1.We have our Flash course open in a new browser window with NO tool bars to optimize size.
    2.The Flash content is scaled to fit the screen - Amlost 97% or more of all graphics are Vector.
    3. We are running into a project that needs to use screenshot .jpgs and we can not get large images from the client.
    4. The .jpgs are being Scaled with the interface and all the FLASH, this is making the client unhappy, and the Jpgs look HORRIBLE, Jaggy.
    Solution: - PLEASE HELP!
    1.  I have searched for days to fix this since we have to keep the whole Flash interface scaling to maximize the Screen area (I don't agree with this but it is the requirements)
    2.  Does anyone KNOW how to make images/jpgs stay a fixed size even while the Flash .swf that the images are in is being scaled?
    3. Any ideas or suggestions are welcome! - I have been searching about HTML and or CSS in Flash and I'm getting lost, not sure if it's possible.  Also I have been exploring dynamically loaded .jpgs in Flash.  Does an FLV scale when using media components?
    Thanks So MUCH!
    Kyle

    you'll need to code that yourself by detecting the scaling used when you go fullscreen (or full browser), and rescale the images (which will need to be converted to movieclips).
    or you could enable the smoothing of your images so their anti-aliased when they're scaled.

  • The latest issue of Pages for iPad: 1. Very slow. 2. Late in reacting to typing. 3. When I go to a specific file, informs me that some images were deleted and therefore file has been changed. Then when OPEN option used, opens file slowly. Please, help!

    What I have to do to correct the following problems with Pages app. For iPad:
    Hesitates to display results of typing, some times for 5-6 characters;
    Very slow in opening files;
    Before opening of a specific file displays message: DOCUMENT DETAILS. SOME CHANGES WERE MADE TO YOUR DOCUMENT. SOME IMAGES ARE MISSING BECAUSE THEY WERE DELETED FROM YOUR DOCUMENT. We'll, nothing is missing. But it takes forever to open this file. The previous issue of Pages worked very good. But they would not let me to go back to it. Please, help!

    Tmobile did the exact same thing to me. So that is customer service at work in general. Nice try though lol.
    To the OP
    I see you said You paid for shipping, did you Insure it? Claim insurance on it. If you did not, It may not be Verizon or your fault in the sense of the phone not making it to the warehouse. There are people out in the postal world that will steal phones that are not insured. It could have been a Verizon employee, i suppose.
    But, if this was to be a bought in court, if you shipped it with out insurance, sadly your at fault.
    Do you still have the Serial number of your old phone? If so, you should be able to track where your phone is (if it is reported as a defect/damaged) If so, you may be able to use that as proof. If it does not show up as a defect or what ever they determine use as a loss, then you know it did not make it to the warehouse to be checked in. I would suspect Apple or Verizon could tell you what the Serial number came up as.

  • Image capture deleted all my photos from iPhone without transferring them to the harddisk. So now I've lost 427 photos due to some data error it says. Please help me get my pictures back!?!

    I just wanted to back up my photos since I haven't done so since October 5th. I plugged in my iPhone and let Image Capture transfer the selected photos to the designated folder. Accidently I hit 'Import All but that's not the biggest problem. Apparently I had "Delete all after transfer" on AND 427 photos apparently "failed to transfer" as it said. I didn't think it was such a big problem, but then I noticed : what the ****.The delete all option was ON and now ALL my photos are gone, from the iPhone and NOT on the computer. Except a list of some old pictures I already have three backups and from the new ones between Oct 5 and this day I have a random selection >><!!!
    So please help me! How do I get my pictures back? iPhone Data recovery? Please please help. There are so many nice memories of this month and I'm so ****** that this just happened!

    If you have iCloud backup turned on or if you have recently backed up via iTunes you could restore the phone from either of those sources. Camera Roll photos are included in those backups. Be aware that doing a restore will replace the contents of the phone with the contents of the backup so you would lose anything new on the phone since the last backup. Back up and restore your iPhone, iPad, or iPod touch using iCloud or iTunes - Apple Support

  • My podcast cover art image has been replaced by the Wordpress bluberry thumbnail in iTunes? Can anyone please help tell me what to do? I made a cover art to the right spec and added it to my podcast episodes in my iTunes library

    The cover art does not show on My iTunes library even when I'm playing it. The cover art does not show in Word press either when you open it on a laptop. But I think I used a feed burner for the podcast and that's why the word press done now has come up. My question is that iTunes have Successfully I did my podcast however my son now is not my heart and I need to change that. Can anybody here please help me? I think it has something to do with the feed burner or potentially the way I have uploaded. I uploaded the podcast directly into WordPress I did not use any other hosting sites like libsyn.

    Giansh2006 wrote:
    I don't quite understand why you have asked me about why I'm keeping my URL secret?
    It's only that I'm not clear why you are reluctant to post it. If you have a podcast in the iTunes Store then it's there for the world to see - they might search on its subject or title, for example, even if they don't actually know about it from you. If you look at other posts in this forum you will see that usually people post their URLs and then I can examine the feed and hopefully find out from that what the problem is. Without this information no-one can give you anything more than wild guesses.
    If you are still reluctant to post the details and want to have a bash at diagnosing the problem yourself you may find my web pages helpful:
    How do I make a podcast?
    how to diagnose a podcast feed
    Why don't my podcast episodes show the podcast image?

  • Live Bookmark Feed failed to load. I cannot view any footage on BBC News site. Also I can no longer view images I have uploaded to a website. This has all materialised overnight. Please help.

    I have been uploading pictures of booksd to ABE.com for ages. I am able to view these images on the site. Today, without warning, I am unable to do this. Coincidentally, I note that I can no longer view film footage on the BBC news pages. The Latest Headlines column is also showing "Live Bookmark Feed failed to load". Please help.

    If images are missing then check that you aren't blocking images from some domains.
    *Check the permissions for the domain in the current tab in "Tools > Page Info > Permissions"
    *Check that images are enabled: Tools > Options > Content: [X] Load images automatically
    *Check the exceptions in "Tools > Options > Content: Load Images > Exceptions"
    *Check the "Tools > Page Info > Media" tab for blocked images (scroll through all the images with the cursor Down key).
    If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.
    Make sure that you do not block third-party images permissions.default.images
    *http://kb.mozillazine.org/Images_or_animations_do_not_load
    There are also extensions (Tools > Add-ons > Extensions) and security software (firewall, anti-virus) that can block images.
    Try to remove the current Latest Headlines feed and create a new feed.<br />
    You can visit http://fxfeeds.mozilla.com/en-US/firefox/headlines.xml

Maybe you are looking for

  • I cant able to create a new Analysis and Dashboard prompt in OBIEE 11g

    Hi Gurus, i try to create a new Analysis in OBIEE 11g in (brower: ie,Google chrome, Mozila), i got the error "*unterminated string literal*" and "*Exception at function updateSelectionsPanel: unterminated string literal*". and i try to create a new D

  • HT200028 i want to use my Apple TV while camping using my hot spot on my iPad as my wireless network.

    I currently have my Apple TV set up using my wireless network in my home.  I plan to use the Apple TV while camping and thinking I should be able to use my Hot Spot on my iPad to display on my TV while camping.  What I'm not finding is how to find my

  • Adobe Photoshop Elements 12: Create Web Photo Gallery

    Adobe Photoshop Elements 12: I need to create a Web Photo Gallery so I can upload thumbnails and full-size pictures to my own website. Does anyone have an idea? No Facebook, Flickr, Adobe Revel etc.

  • PIN sign-in GPO not applying to workstations

    I am currently testing Windows server 2012 R2 with Windows 8.1 tablets and cannot get PIN sign-in to work on the client machines, I have disabled local policy processing and all of the management is coming from GP, however when I manually apply the p

  • Cannot install perl modules

    Hi team, I’m trying to do a little perl script to telnet some cisco equipment. I’m trying to install some perl module through CPAN but I was got an error. Output is the following. Any ideas? Using MAC OSX 10.6.4 cpan[13]> install Net::Telnet:Cisco Ru