How can i copy a specify area of the BufferedImage?

hi all,
i consider this is a difficult level question and i do really need this urgently, please anyone who help me, thank in the first place.
here the question:
i have create an applet where it draw the character string into an buffered image using drawString(...); i have set the rendering option enabled. now the problem is that this drawn character is draw on the buffered lmage with both horizontal and vertical "gap", but i do not want it in that way, i want to make it exactly "fit" to the buffered image size. because after which i will "enlarge" this character to draw up a larger image, if this gap's is not eliminate, then after the enlargement process, there is a significant "white space gap" which is not nice to see (for me). anyone can help?
thanks

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class StringSize extends JPanel
    BufferedImage image;
    Font font;
    public StringSize()
        font = new Font("lucida sans demibold", Font.PLAIN, 36);
        createImage();
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        int w = getWidth();
        int h = getHeight();
        int x = (w - image.getWidth())/2;
        int y = (h - image.getHeight())/2;
        g.drawImage(image, x, y, this);
    private void createImage()
        int w = 240;
        int h = 100;
        image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(new Color(200, 220, 240));
        g2.fillRect(0,0,w,h);
        String s = "hello world";
        g2.setFont(font);
        FontRenderContext frc = g2.getFontRenderContext();
        TextLayout layout = new TextLayout(s, font, frc);
        Rectangle2D bounds = layout.getBounds();
        //String sb = bounds.toString();  // [x=3.25,y=-27.75,w=203.375,h=28.1875]
        //System.out.println("bounds = " + sb.substring(sb.indexOf("[")));
        double width  = bounds.getWidth();
        double height = bounds.getHeight();
        double xScale = w/width;
        double yScale = h/height;
        //System.out.println("width = " + width + "\theight = " + height + "\n" +
        //                   "xScale = " + xScale + "\tyScale = " + yScale);
        AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
        g2.setFont(g2.getFont().deriveFont(at));
        float dx = (float)(bounds.getX()*xScale);
        float dy = (float)((bounds.getY() + bounds.getHeight())*yScale);
        g2.setPaint(Color.red);
        g2.drawString(s, -dx, h - dy);
        g2.dispose();
    public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new StringSize());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How can I know which photos are in the library was used in each album I have created before.

    How can I know which photos are in the library was used in each album I have created before?
    I have many photos in the library folder of iPhoto, but actually I don't know which photos were used in my album.
    Is there any method to find this?
    Thanks.

    Album or Book?
    If Album you can find the ones not already used:
    File -> New Smart Album
    Album -> is not -> Any
    Regards
    TD

  • How can I copy about 2000 photos off the Ipad 4?

    A friend has a 16gb Ipad 4 which now shows 800mb free space, due to the fact that it's filled with photos, sitting in Iphoto.  He cannot update anything now due to being out of space, so he has asked me to help him move the photos off to another machine and then delete them from the Ipad.  He apparently has no other copies of these shots.
    After reading dozens of posts about this, it appears to me that there really isn't any coherent method of simply marking and copying photos once they're in Iphoto on the Ipad 4.  After connecting it to the Mac via the USB cable, there's not much that is revealed.  And viewed from Windows, the DCIM folder which is where we generally expect to find these things shows only 13 photos.  Where are the rest of them?
    All I have found is that I'll have to use an "external application" to do this; however, installing several of these has led me to being able to only copy the "new pictures" that apparently are on his camera roll.  There are only about 13 of these.  Another app led me to being able to copy albums, but he only has about 177 of the photos identified as being in an album.
    So that leaves the thousands of shots that sit in Iphoto, apparently marooned.  Is it really possible that the only way to get these photos is to go though some sort of sync process with itunes or icloud?
    Seems fairly clunky to me.  I would expect to be able to simply mark a folder, and drag it "somewhere else" rather than going through all the hoops it appears to require to do this.
    Anyone?
    Bueller?
    Thanks,

    How to Transfer Photos from an iPad to a Computer
    http://www.wikihow.com/Transfer-Photos-from-an-iPad-to-a-Computer
    Importing Personal Photos and videos from your iOS device to your computer.
    http://support.apple.com/kb/HT4083
    iTunes: Frequently asked questions about viewing and syncing videos
    http://support.apple.com/kb/HT2729
    Also check out the Photo Manager Pro app.
    https://itunes.apple.com/us/app/photo-manager-pro/id393858562
    Check out the Feem WiFi File Transfer app
    https://itunes.apple.com/us/app/feem-wifi-file-transfer-free/id596378699?mt=8
    This may help to free up more space.
    iPhone, iPad, and iPod: Understanding capacity
    http://support.apple.com/kb/ht1867
    How much space is used by your Other? You may be able to reduce.
    How Do I Get Rid Of The “Other” Data Stored On My iPad Or iPhone?
    http://tinyurl.com/85w6xwn
    How to Remove “Other” Data from iPhone, iPad and iPod Touch
    http://www.igeeksblog.com/how-to-remove-other-data-from-iphone/
    With an iOS device, the “Other” space in iTunes is used to store things like documents, settings, caches, and a few other important items. If you sync lots of documents to apps like GoodReader, DropCopy, or anything else that reads external files, your storage use can skyrocket. With iOS 5/6/7, you can see exactly which applications are taking up the most space. Just head to Settings > General > Usage, and tap the button labeled Show All Apps. The storage section will show you the app and how much storage space it is taking up. Tap on the app name to get a description of the additional storage space being used by the app’s documents and data. You can remove the storage-hogging application and all of its data directly from this screen, or manually remove the data by opening the app. Some applications, especially those designed by Apple, will allow you to remove stored data by swiping from left to right on the item to reveal a Delete button.
    What is “Other” and What Can I Do About It?
    https://discussions.apple.com/docs/DOC-5142
    iPhone or iPad Ran Out of Storage Space? Here’s How to Make Space Available Quickly
    http://osxdaily.com/2012/06/02/iphone-ipad-ran-out-of-available-storage-space-ho w-to-fix-quick/
    6 Tips to Free Up Tons of Storage Space on iPad, iPhone, and iPod Touch
    http://osxdaily.com/2012/04/24/6-tips-free-up-storage-space-ipad-iphone-ipod-tou ch/
    Also,
    How to Clear Message/iMessage Cache on iPhone & iPad And Reclaim Lots of Free Space
    http://www.igeeksblog.com/how-to-clear-message-imessage-cache-on-iphone-ipad/
    What is Stored in iCloud and What is Not
    https://sites.google.com/site/appleclubfhs/support/advice-and-articles/what-is-s tored-in-icloud
     Cheers, Tom

  • How can I copy and paste events in the calendar?

    Does anyone know how to cut and paste or copy and past events in the calendar?  The events happen at different times and on different days so I can't just "repeat".  Thanks in advance!

    Ignore MJG196 post.
    In Calendar, tap the event, tap Edit, then change the Starts date you want the event to move to.

  • How can I copy linked properties without losing the link to the control?

    I've been dealing with an annoying issue when copying/pasting properties. If the properties are linked to a control when I copy them, they lose that link in the pasted version.
    Basically, copy/paste is not really following the expected behavior of "copying" in that the resulting "paste" is different from the item being copied. Is there a way around this besides having to manually go to each one and re-link it?
    Below are snippets to demonstrate the problem:
    Before Pasting
    After Pasting:
    Solved!
    Go to Solution.

    The behavior you're seeing is, unfortunately, not unique to you. It's the way LabVIEW works. Until enough people complain and get NI to change it, that is. Omar's link to the proposed idea is one.
    An alternative is to right-click and drag. This creates a copy. At least when you're within the same VI, that is. This, and other nifty tricks can be found in the Quick Reference Card.

  • How can I find which applications are using the most power?

    I have recently noticed a full charge of power doesn't last as long as it used to on my iPad 2.  Is there some way to determine which applications are using the most power?
    I have been monitoring my home network router accesses and have noticed the iPad logs accesses every 15 seconds.  This only happened recently.  It had been well behaved and only accessing once or twice a day before.  I installed the most recent iTunes upgrade, per suggestions during a Sync.  The problems seemed to occur after this update.  I have gone through all the settings and have minimized the applications requiring higher power (I switch off the location services unless I'm away from home.  Likewise, I turn off my cellular carrier unless I'm away from home, etc.)
    In short, how can I maximize my power usage (aside from turning it off)?
    Thanks.
    Dave

    Thanks for responding so quickly.
    I'm really trying to find out why the battery is depleting much faster than it used to all of a sudden.  I used to be able to put a full charge on it and it would last about 5 to 6 days with normal use (normal for me).  Now that battery only lasts about 2 to 3 days with the same use.
    I DO recharge it when it needs to be charged but this is indicating there is something else (new) that is causing the power drain.

  • How can I install downloads which are IN the download file, but not accessible or usable?

    I often get the message to download a new flash player.
    I click on the download button and nothing happens.
    I tried disabling the firewall on Firefox. I still couldn't get the flash player to download.
    Other, minor downloads have downloaded, and are in the download file. But they do not work, or are not installed, or somehow they are not usable or accessible to use.'''bold text'''

    Drag/drop the picture you want to add on the area with the other thumbs.

  • How can I copy an email address from the form results while online?

    Our form contains a field where the users submitted their email address.  But I am not able to mouse over this data in the "View Responses" tab, and copy the email address by selecting the email address and Ctrl C, and neither can I right-click this data field and copy it.
    Our organization just switched to Microsoft Office 365, and "mailto" links on web pages can no longer be clicked to launch a native desktop email client program.  So the users tasked with responding to forms submitted via Formscentral now have a much harder workflow.  They are compelled to download the data as a spreadsheet, just to be able to cut and paste an email address into their reply email.
    I suggest and request that the Flash-based "View Responses" tab be modified to allow email addresses to be selectable and able to be  copied to the "clip board".  This would allow users who can't execute a clickable mailto link to copy and paste the email address from Formscentral into a new email.  Many organizations like mine are moving away from native client-based email programs like Outlook to save money,  in favor of cloud based SAS web-based email like Office 365.
    Is there some other way to enable mailto links where no client email program is installed on the users PC?
    Thanks,
    -Dave Bartholomew

    While I am still looking for a better answer, I've discovered a way to cut and paste email addresses from the FormsCentral "View Responses" dashboard.  I wrote up the instructions to help our users and thought I'd share them in this forum as well.
    But it would be nice if there was a simpler solution...  Can anyone offer a better way?
    -Dave B
    ) Right-click on the email address
    ) Select “Filter by: …”  Doing this will change the view to show only entries that were sent from the selected email address.
    ) And it will display the Filter in the header of the form.
    ) Left-click on the email address displayed in the filtered results, in the header of the form.
    ) A new sub-form will appear, and the email address can be cut and pasted from this new sub-form.  Highlight the email address and hit “Ctrl C”, or right-click and select copy.
    ) Now you can paste the email address into a new email in Office 365. (Ctrl V) or right-click and select “Paste”
    ) Click the “Clear” button and then “OK” to exit the filtered view of the data.

  • How can I copy text as-is from the address bar?

    Hi there,
    I use numerous username/password combinations to log onto an ftp site in the following form:
    ftp://fairlyShortUsername:[email protected]
    E.g. ftp://moduleFour:[email protected]
    Using this method allows me to log straight in because username and password are stored right inside the url.
    Due to their convenience, it is useful to be able to pass these links around to others.
    If I start typing the username (e.g. 'moduleF'...) in the address bar, the complete URL appears in the autocomplete suggestions and I can use the down arrow to display it in the address bar and copy it to the clipboard.
    However, when I paste what I copied (taking the above example), I just get ftp://ftp.site.com. This is no use to anyone without the information that has been stripped out.
    I'm not concerned with security (understandably, given that I'm using urls with plain text passwords).
    I'm sure firefox is just trying to be 'helpful', but is there any way I can copy the exact text displayed at the time I press Ctrl + C, without firefox interfering? At the moment, I have to look up the username and password and paste them into a url template every time, which given the number of times I've done it, has already taken up more time of my life than it's taken me to write this question, which is why I'm asking.
    *** NOTE: Changing the value of browser.urlbar.trimURLs and browser.urlbar.formatting.enabled has *not* allowed me to fix this. ***

    Okay, I think one of these add-ons is just what you need.
    Go to the '''[https://addons.mozilla.org/en-US/firefox/ Mozilla Add-ons Web Page]''' {web link}
    (There’s a lot of good stuff here) and search for what you want.
    '''[https://addons.mozilla.org/en-US/firefox/addon/my-copyfixer My CopyFixer ]''' {web link}
    Use Ctrl+C when nothing selected to copy page title and url in
    various format (template base).
    '''[https://addons.mozilla.org/en-US/firefox/addon/send-tab-urls/ Send Tab URLs]''' {web link}
    Send a list of browser tab URLs to email, Web mail, or the clipboard

  • How can I copy an image/picture from the internet into a word document

    I am trying to copy and paste an image or picture from the internet and insert it into a word document. I select and copy the image from the internet page. I then go to the word document and select past special. When I select 'paste special' it only allows text to be copied and no images or pictures. If I also try to drag the image and place it in the word document. It does not allow me to do so. Any suggestions to fix this issue?

    Considering this is a MS Word issue I'd recommend reposting to that forum. You can find one at:
    http://www.officeformac.com/productforums/
    Regards,
    Roger

  • How can I load a content area in the floor plan manager?

    Hi Guys,
    I´d like to load a content_area (Page 1 Initial Screen) from another (Page 2 Main screen). Basically, I want to go back to the initial screen from the main screen.
    How could I do this? (A piece of code would be very useful).
    Thanks

    Finally, I only called to the correct event.
    lr_event = cl_fpm_event=>create_by_id( cl_fpm_event=>GC_EVENT_START ).
    lo_fpm = cl_fpm_factory=>get_instance( ).
    lo_fpm->raise_event( lr_event ).
    Thanks.

  • How can I copy a video to flash drive

    How can I copy a video saved in the Mozilla history to a flash drive?

    First, format the flash drive as HFS Extended (Journaled).
    Then drag and drop the entire TS folder (which makes up a video DVD) from your desktop to the flash drive.

  • How can I copy outlook files to hard drive

    How can I copy large outlook files to the external hard drive with out formatting it?
    I currently have Macbook Pro Version OS X 10.9.5.
    I tried all the ways copying outlook files, but it says larger files cannot be transferred. My outlook file is about 16gb.
    Also tried trough Time Machine...Can anyone list of the steps here to copy these files to my hard drive?
    Later, I want to copy these files from hard drive to the new Macbook Pro.....need urgent help please !!!

    If your external drive is FAT32 (MS-DOS) format, it won't take file larger than 4GB. There's no way around that, I'm afraid.
    Matt

  • I have a DVD I recorded from my tv.  I am trying to make copies and when I insert the DVD I get a message saying it is blank even though it is not.  My question are: Why does my computer think it's blank? And how can I copy a DVD?

    I have a DVD I recorded from my tv.  I am trying to make copies and when I insert the DVD, I get a message saying the DVD is blank, which it is not.  My questions are: Why does my computer think it's blank?  And how can I copy the DVD providing my computer recognizes there is content on it?
    Thanks, Sheila

    TV video typically is copyrighted content.  We'd be breaking several rules trying to help you.  Good luck!

  • How can I copy my music files to my iPAD. The CDs are currently stored in folders on my PC. Note: Synching via iCLOUD won't work because I have VISTA OS and I need at least Windows 7 or 8.

    How can I copy my music files to my iPAD. The CDs are currently stored in folders on my PC. Note: Synching via iCLOUD won't work because I have VISTA OS and I need at least Windows 7 or 8.

    Hi ladextr,
    Thanks for using Apple Support Communities.  To sync your music to your iPad, first put your music in iTunes as described here:
    Adding music and other content to iTunes
    http://support.apple.com/kb/ht1473
    Adding content on your computer to iTunes
    iTunes helps you add digital audio and video files on your computer directly to your iTunes library. You can add audio files that are in AAC, MP3, WAV, AIFF, Apple Lossless, or Audible.com (.aa) format. If you have unprotected WMA content, iTunes for Windows can convert these files to one of these formats. You can also add video content in QuickTime or MPEG-4 format to iTunes. To learn how to add these files to iTunes follow the steps below.
    Open iTunes
    From the File menu, choose one of the following choices:
    MacAdd to Library
    Windows
    Add File to Library
    Add Folder to Library
    Navigate to and select the file or folder that you want to add
    If iTunes is set to "Copy files to the iTunes Music folder when adding to library," iTunes will copy all content that is added to the iTunes library to the iTunes Music folder. To adjust this setting or change the location of this folder, go to the Advanced tab in iTunes Preferences.
    Once that's done, you can sync the music to your iPad by following this article:
    iTunes 11 for Windows: Set up syncing for iPod, iPhone, or iPad
    http://support.apple.com/kb/ph12313
    Cheers,
    - Ari

Maybe you are looking for