How do you get a subImage that is not a rectangle?

I need to extract a portion of an image that is not rectangular. I know if I convert my image to BufferedImage I can use its getSubImage() to return a rectangular image. However what if I wanted a different shape? I've not found any method that returns a more general shaped image.
All I can think of doing is, say for a triangle, something like this:
       x
     xxx
   xxxxx
xxxxxxxie, a series of getSubImage()s that are one pixel high and a variable length long. Is there any better way to do this? I was hoping for a getPolygon() method.
Joe

Hi, there are several ways to do what you want to, but you have to understand that an object of type "Image" or "BufferedImage" is always rectangular. It has "width" and "height" properties which are dimensions of a rectangle. Suppose you have an object shape instance of Shape:
Shape shape = ...;
You have to create an image (rectangular of coarse) in which the pixels out of shape are transparent:
Rectangle rect = shape.getBounds();
int x = rect.x;
int y = rect.y;
int w = rect.width;
int h = rect.height;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = bi.createGraphics();
g.setColor(new Color(255, 255, 255, 0));
g.fillRect(0, 0, w, h);
Now you have to fill the shape with the pixels from the source image (original):
g.setClip(shape);
g.drawImage(original, -x, -y, null);
That's all! Note that the image you created has a type BufferedImage.TYPE_4BYTE_ABGR but the source may have any other type. If you have to preserve the type of the original image you have to do something else.
The complete method:
BufferedImage getSubImage(Shape shape, BufferedImage original){
Rectangle rect = shape.getBounds();
int x = rect.x;
int y = rect.y;
int w = rect.width;
int h = rect.height;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = bi.createGraphics();
g.setColor(new Color(255, 255, 255, 0));
g.fillRect(0, 0, w, h);
g.setClip(shape);
g.drawImage(original, -x, -y, null);
g.dispose();
return bi;
}

Similar Messages

  • How do you get your information, that's on your icloud, something was taken off my notes that should be back-up in my icloud. Help

    How do you get your information, that's on your icloud, something was taken off my notes that should be back-up in my icloud. Help

    The syncing of Notes, isn't a back-up. All it does is to sync Notes to other devices. Whether being a Mac, another iOS device or icloud.com
    This is the same with Contacts, Calendars and what not.
    KOT

  • HT201272 How do you get your files that are hidden in the cloud?

    How do you get your files that are hidden in the cloud?

    What files are you looking for?
    GB

  • How do you get your text messages to not show on the screen when they come in

    How do you get your text messages to show on the screen when then come in?  My iphone 3s would just say the persons name and text message.  This says the persons name and the whole message

    Settings > Notifications > Messages > Show Preview - Turn to OFF

  • How do you get songs back that have been lost in a computer crash?

    About 2 months ago my windows had crashed. We fixed it and everything but noticed that all of the songs from my account disappeared. The file name was there but the actual song would not play. If i am to click on one it would say this.
    The song " anything" could not be used because the original file
    file could not be found. Would you like to locate it"
    It would have an option where you could click yes or no. The first time it happened, I clicked on the yes and it would have me browse through all my files, of course none of the songs found. I have all the songs that I really wanted on my ipod nano still. Is there a way to load these songs back on the computer? Some of the songs are from cds as well as purchased from itunes.

    If you have any iTunes Music Store purchases the transfer of purchased content from the iPod to authorised computers was introduced with iTunes 7. You'll find details in this article: Copying iTunes Store purchases from your iPod or iPhone to a computer
    The transfer of content from sources such as songs imported from CD is designed by default to be one way from iTunes to iPod. However there are a number of third party utilities that you can use to retrieve the music files and playlists from your iPod. You'll find that they have varying degrees of functionality and some will transfer movies, videos, photos, podcasts and games as well. Have a look at the web pages and documentation, this is just a small selection of what's available, they are generally quite straightforward. You can read reviews and comparisons of some of them here:
    Wired News - Rescue Your Stranded Tunes
    Comparison of iPod managers
    TuneJack Windows Only (iPhone and iPod Touch compatible)
    iPod2PC Windows Only
    iDump Windows Only
    SharePod Windows Only
    iPodRip Mac & Windows
    YamiPod Mac and Windows
    Music Rescue Mac & Windows
    iPod Music Liberator Mac & Windows
    Floola Mac & Windows
    iGadget Mac & Windows (iPhone and iPod Touch compatible)
    iRepo Mac & Windows (iPhone and iPod Touch compatible)
    iPod Access Mac & Windows (iPhone and iPod Touch compatible)
    TouchCopy Mac & Windows (iPhone and iPod Touch compatible)
    There's also a manual method of copying songs from your iPod to a Mac or PC. The procedure is a bit involved and won't recover playlists but if you're interested it's available on page 2 at this link: Copying Content from your iPod to your Computer - The Definitive Guide
    I would also advise that you get yourself an external hard drive and back your stuff up, relying on an iPod as your sole backup is not a good idea and external drives are comparatively inexpensive these

  • TS3406 My iPhone 4S will not ring. It comes up on screen to accept or decline. How do you get rid of that so it rings and just answer the phone

    My iPhone 4S will not ring when a call comes in. It comes up on the screen to accept or decline. How do you remove that so it will ring and answer a call normal

    See Here...
    Troubleshooting applications purchased from the App Store
    The Basic Troubleshooting Steps are:
    Restart... Reset... Restore from Backup...  Restore as New...
    Restart / Reset
    http://support.apple.com/kb/ht1430
    Try this First... You will Not Lose Any Data...
    Turn the Phone Off... ( if it isn’t already )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear and then Disappear...
    Usually takes about 15 - 20 Seconds... ( But can take Longer...)
    Release the Buttons...
    Turn the Phone On...
    If that does not help... See Here:
    Backing up, Updating and Restoring
    http://support.apple.com/kb/HT1414

  • HT1711 how can I get album tracks that do not properly download?

    I lost two tracks during download. How can I get them without rebuying?

    Welcome to the Apple Community.
    Try deleting the problematic file (electing to remove original file if/when prompted) and then re-downloading the file from the iTunes store.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option from the Quick Links section in the top right corner of the iTunes homepage in your iTunes application on your computer.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option at the bottom of the screen of the iTunes app (or video app) on your iOS device.
    If the problem re-occurs, select the content which is causing a problem and use the 'Report a problem' button in Your Purchase History using your computer.

  • How do you get funded for app do not want

    I got some app that I did not want now they will not let me get on my acc they keep asks for a new card

    On the receipt you get is an offer to report a problem.    Respond to that with the problem you have found.   But before you do, check the situation out with the developer; they may have an answer and Apple will expect you to have done this.

  • HT201320 how so you set up email that is not hotmail, gmail, etc..?? every time i try to add an account, it doesnt work

    How do you set up email on iphones that are not icloud, exchange, gmail, yahoo,aol, or hotmail?

    I'm thinking you sync to your computer over Wi-Fi, if correct, switch to sync when connected to iTunes, turn off sync over Wi-Fi. Hope this helps, Good luck. Cheers.

  • How do you get your ringtone that you bought on your iPad to your Iphone

    I bought several ringtones on my iPad because its a lot faster and I thought it would automatically sync to my iPhone like all my songs. But now I can't find the ringtones anywhere except my iPad sounds. It's not in my purchases or in my iCloud. Idk how to download it to my iPhone whiteout buying it again because that's like a total rip off. So if anyone can help me that would be great. :)

    Transfer your purchases to your computer, as you should on a regular basis anyway.  Sync the other device with the updated iTunes library.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only purchases from iTunes Store
    As you have discovered, ringtones can only be downloaded once so there is no other way to do it.

  • How do you get rid of that compass?

    Can you help me get rid of the compass that appears in photoshop sometimes?  I don't know what it's there for...  Thanks! 

    That's probably the compass you see when having the Rotate View Tool selected

  • How do you get the screensaver that takes your iPhoto pictures and make one big picture? Used to have it on 10.6.8 but cant find it

    Used to have it on 10.6.8 but cant find it. It took all the pics from iPhoto I think then made a pic out of them as a screen. Help?

    Ah, welcome to my world...the world of progressive vs interlaced, RGB vs YUV, compression/decompression,10 bit or 8 bit, 4:4:4 vs 4:0:1 vs 4:1:2, color space (etc, etc, etc..!)
    There's HD, DV, HDV, NTSC, PAL and more - its a place where acronyms roam free and multiply daily.
    You're in for a fascinating journey that will soon have you understanding things you never dreamt you'd need to know, then when you think you've got to grips with 'em, you'll discover you don't really know the first thing about them...!
    Fortunately you've got Bogie, Patrick, Shane, David and more to take you along for the ride.
    I will suggest (and probably be corrected) that what you're seeing is probably interlaced footage on your progressive monitor. (You mentioned you're watching the DVD on your computer.) Your TV has far fewer lines of resolution than your computer monitor, so FCP works within those constrictions. Also your TV runs at 29.97 frames a second, which is actually 60 frames a second as each frame is divided into two fields, which comb together to for one frame. These combs are very much evident when watching a DVD on a computer. Even high budget Hollywood films have this problem, especially when the camera or subject is moving. There is no way around this if you're outputting on DVD or NTSC.
    You could create an Progressive file, which won't do this on your monitor, but thats a whole other ball of wax...
    Welcome though. Its all good. (And the people on this site are very helpful, I've learnt a lot over the last 5 years by simply reading these posts.)

  • How do you get the indicator that marks emails as "read" to work properly?

    Every time a new email comes in it's never marked as unread. The computer is on a wired network in an office where no other Mac users have this problem. The usual diagnostics have been performed and the computer seems normal in all other operations. Any ideas? The office geeks are stumped as well.

    There's an option in Mail > Preferences > viewing tab > check "Display unread messages with bold font".
    Regards,
    Captfred

  • HT1491 how do you get ringtones back that you've bought?

    i have bought four or five ringtones. After i have synced my iphone 4gs to my new computer they all dissapperd except for one. When my phone is plugged into my computer i can click on my phone and click the tones and it'll show the songs there and the wording is all grey. it wont let me download them on to the computer or on my phone. i cant find them on my phone at all. and i dont want to have to buy them over again.

    i went to itunes on my phone and into my purchased. And it doesnt show the tones.
    the tones dont show up on my account at all untill my phone is plugged in and i click on it through there. but like i said it wont let my do anything

  • How Do You Get BO/Web-I To Not Show Duplicate Serial Numbers...

    (Running Business Objects Release 2 (Web-I), No other reporting modules)
    I have a "test" report for our product that we produce.  Currently the report pulls in all tests in a given period.  I want it to only pull in the "first test of the product", so I can measure what is called First Pass Yield"  To do this I only want the first test of the product to show up. 
    Below is an example of the report.  I have made the text "bold" for the rows which I do not want shown in the report (please note that I do not want the information deleted from the database, just not shown in this report)
    Information about the report that you need to know to help:
    1. The product is serialized.
    2. Sometimes our product is tested several times in a given month if there were problems with it or it was upgraded during that month.
    So, when I run a report for the month it shows the serial number in the first column, the test date and time in the second column and the test results in the third column.  So the report will look something like this:
    Board SN - - - - - - - - - -Test Date - - - - - - - - - - - - - -Test Results
    1508-00641 - - - - - - - - 11/3/2008 8:40:22 AM - - - - -Passed
    1508-00542 - - - - - - - - 11/3/2008 8:50:12 AM - - - - -Passed
    1508-00543 - - - - - - - - 11/3/2008 3:18:00 PM - - - - -Failed - Defective Part
    1508-00543 - - - - - - - - 11/3/2008 3:23:05 PM - - - - -Failed - Out of Tolerance
    1508-00543 - - - - - - - - 11/3/2008 4:00:43 PM - - - - -Passed
    1508-00847 - - - - - - - - 11/3/2008 4:07:51 PM - - - - -Passed
    Any help in getting the report to display the way that I want is appreciated.
    Charles
    Edited by: Charles Norman on Nov 20, 2008 1:43 PM

    Hi Charles,
    WEBI treats each column as single entity hence we canu2019t perform operation on particular value in column; also we canu2019t refer all values in record at a time.
    I Tried applying filter at Universe level without modifying DB but I couldnu2019t find suitable functions like RunningCount in WEBI.
    In WEBI you can use =RunningCount([Test_Date];([Board_SN])) using this we can count the number of tests performed for each product
    Board SN - - - - - - - - - -Test Date - - - - - - - - - - - - - -Test Results                              Test
    1508-00641 - - - - - - - - 11/3/2008 8:40:22 AM - - - - -Passed                                          1
    1508-00542 - - - - - - - - 11/3/2008 8:50:12 AM - - - - -Passed                                          1
    1508-00543 - - - - - - - - 11/3/2008 3:18:00 PM - - - - -Failed - Defective Part                     1
    1508-00543 - - - - - - - - 11/3/2008 3:23:05 PM - - - - -Failed - Out of Tolerance                  2
    1508-00543 - - - - - - - - 11/3/2008 4:00:43 PM - - - - -Passed                                           3
    1508-00847 - - - - - - - - 11/3/2008 4:07:51 PM - - - - -Passed                                           1
    But the Problem is either we can display whole duplicate records or we can suppress all duplicate records based on the Board SN. But canu2019t display only first record. Because the variable I created is at report level I canu2019t use it query panel query filter.
    You can try following solution if it is feasible for you to modify DB a litte Bit as this modification in DB is also useful to track no. of test performed for each product.
    1) Add column in DB as Tests_performed and add Serial No. as 1,2,3 for each product tested for each test.
    2) Refresh the Universe structure. (View -> Refresh Structure ) 
    3) Modify the universe by creating new object ( Test_performed)  based on that column.
    4) Export it to repository
    5) Open WEBI use that object in query filter and use condition as Test_performed <2
    6) You will get the data you want.
    I hope it is Helpfulu2026.
    Thanksu2026.
    Pratik

Maybe you are looking for

  • Z Database view is not showing all the entries?

    Hello Last year I have created a Z table, say, its name is Z_TABL_1, its working fine, say, there is around 1000 entries in PRD, well Last week I have created another 2nd Z table, its name is Z_TABLE_2, now it has 50 entries in PRD In both tables the

  • GETWA_NOT_ASSIGNED error while running abap prog in process chain

    Hi. I am getting a runtime error GETWA_NOT_ASSIGNED while running an ABAP program in process chain. But when i execute pro in SE38 , it's not giving any error. Please any one can suggets what will be error.

  • Variants on tabbed selection screen for ALV reports

    Scenario: We use a tabbed selection screen for an ALV report. We create a variant, make a selection field on the second tab mandatory & save it without a value. When we run the report with the saved variant it does not check that the required field o

  • ApplicationPool / Caching

    Hi, 1.) when i use an ApplicationPool and the sessions are checking out and in the ApplicationModules, must i reset the ApplicationModules via remove or the views via reset, to prevent the next session to get get the states and the entity-cache from

  • SQL 2012 AlwaysOn upgrade to SQL 2014

    Anyone have some info regarding inplace upgrade from SQL 2012 AlwaysOn to SQL 2014 ? -Arnstein