Creating BufferedImage from int[] (not RGB's)

Hi,
I have an int[] that contains how many intersections occur between each pixel and a series of overlapping rectangles. So the array would look like this:
int [] intersections = { 0,1,1,1,1,0,2,4,4...etc} each number representing the number of times each pixel intersects a rectangle.
What I would like to do is create a bufferedImage where each pixel in the image is a color based on the number of intersections from the array. 0 intersections is transparent, 1 intersection is a blue pixel , 2 intersections is green etc.
I implemented it first looping through the array and painting a 1X1 rectangle colored according to the number of intersections but it is slow. Can I use a ColorModel for this (never used one)?. If so, what is a good method to convert these integers that represent the number of intersections to the corresponding color in a BufferedImage? The maximum number of intersections would be far fewer than 256, probably in the range of 10-50. I would also like to create the image in grayscale, the larger number of intersections getting darker and as hues of one color where an index of 0 would be transparent and as the number of intersections got larger the color gets darker. It all works the way I did it but it is way too slow. Will a ColorModel do transparent pixels? Is MemorySourceImage a good way to do this? Any ideas?
Thanks very much!
Paul

You're more or less describing a IndexColorModel, except the data bank is usually a byte[]:
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
public class IndexColorModelTest {
    public static void main(String[] args) {
        int w = 300, h = 200;
        BufferedImage bi = createImage(w, h, createData(w, h));
        JLabel label = new JLabel(new ImageIcon(bi));
        label.setOpaque(true);
        label.setBackground(Color.RED);
        final JFrame f = new JFrame("IndexColorModelTest");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(label);
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                f.setLocationRelativeTo(null);
                f.setVisible(true);
    static byte[] createData(int w, int h) {
        byte[] data = new byte[w*h];
        new Random().nextBytes(data);
        return data;
    static BufferedImage createImage(int w, int h, byte[] data) {
        //create a color model with grays
        int SIZE = 256;
        byte[] gray = new byte[SIZE];
        for(int i=0; i<256; ++i)
            gray[i] = (byte) i;
        ColorModel cm = new IndexColorModel(8, SIZE, gray, gray, gray, 0); //0 is transparent pixel
        DataBuffer db = new DataBufferByte(data, w*h);
        WritableRaster r = Raster.createInterleavedRaster(db, w, h, w, 1, new int[]{0}, null);
        return new BufferedImage(cm, r, false, null);
}

Similar Messages

  • Creating bufferedimage from scene in different resolution than the Canvas?

    Is it possible to create a bufferedimage from a Canvas, but with a higher resolution without loosing image quality?
    Need to take high-quality screenshots of the 3d-scene.
    Thanks.

    I'm trying to back up and simultaneously organize my photos from my Mac OS 10.8.5 by dragging groups of photos from iPhoto to an external HD.
    One more thought -  if you want to backup your photos, why not simply copy your iPhoto Library to the external drive? That would save your photos as well as the work you invested in editing and tagging them.
    If you do the backup by storing only the photos on your external drive, you need to export all edited photos twice - first the original photo like described in Old Toad's screenshot, and then the edited version as well, or you will lose your editing work, if you need your backup.
    Copying the iPhoto Library would save all in one, without too much trouble.
    Your second goal, reorganizing, could be done directly in iPhoto.

  • Creating BufferedImage from Image

    I've figured out one way to create a BufferedImage from an Image, but I'm sure it's not the best way.Image im = Toolkit.getDefaultToolkit().getImage(files.getAbsolutePath());
    JLabel jl = new JLabel(new ImageIcon(im));
    BufferedImage bim = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = bim.getGraphics();
    jl.paint(bim.getGraphics());
    This works, but I'm sure there has to be a better/easier way. Any suggestions?
    Thanks,
    m

    close, the best way is this...
    public BufferedImage createBufferedImage(Image img)
    BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);//or whatever type is appropriate
    bimg.getGraphics().drawImage(img,0,0,null);
    return bimg;
    }

  • Create ISO **FROM** CD (**NOT** burn ISO back to useable CD) ??

    OK, I can't seem to find information anywhere about how to create an ISO file...Tons of info about creating CD from an ISO but that's not what I need...
    PLEASE NOTE BEFORE RESPONDING that I DON'T want to take an ISO file and create a DVD with it, which can be done in OSX's built in disk utility.
    As a "for instance", I'd love to create an ISO file from my MacOSX disk and store the ISO on a backup drive, so that in the event I scratch the @$*U#$ out of the original disc, I can create a new one without a fuss...
    Thanks much for the info

    Yes, the extension is .CDR, but it doesn't really have anything to do with a CD in particular. It's an exact copy of the contents of whatever disk you create the file from. It doesn't have a .ISO extension, but it's the same thing.
    Whether or not you could just change the extension and have it work, I don't know, but there's no need to do that. Unless you were to try and use the file on a PC to create a new disk and would have to change it in order for the software you use there to recognize the file as a disk image. On the Mac, you would just use it as is to burn your duplicate.

  • Create SPFILE from pfile not working

    Experts,
    I have edited SPFILE by mistake....but.... I do have a good pfile and am able to startup oracle from pfile.
    I am trying create SPFILE from pfile:
    create spfile='path/file' from pfile='path/file'
    as soon as I execute this command prompt is showing as follows:
    c>: 2
    and is expecting some reponse, if typein some char like:
    c>:2 AAAA,,, reponds back:
    c>: 3 (expecting response again)
    Please let me know what could be wrong.
    I am connected as SYSDBA...
    Your help will be greatly appreciated.
    Venkat

    create spfile='path/file' from pfile='path/file'It's expecting a command termination : try adding a semicolon, e.g.
    create spfile='path/file' from pfile='path/file';
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14357/ch4.htm#sthref829

  • Kuler's Create colors from image not working

    Whenever I try to create a color scheme from a photo, the
    little spin graphic hangs and the percentage done gets stuck on 19%
    or 31%. It's not working. Any help??

    Hi,
    We were experiencing issues with one of our servers
    yesterday. It should all be working now. Please let us know if
    you're still experiencing the same problems.
    Thanks,
    The Kuler Team

  • Create CLOB from string not coming from ResultSet

    I need to populate a preparedStatement parameter
    using setClob(). The data which goes into the parameter
    is a String. I need to convert the string to a Clob. How do
    I do this? The String is over 4000 characters long and
    will be entered into an Oracle CLOB field.
    Any tips?

    The Oracle JDBC documentation has a section on using Blobs and Clobs that should answer your question:
    http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oralob.htm#1043220

  • PS: WBS is not flowing for a Material, while creating delivery from Project

    Hi,
    While creating delivery from Project thro CNS0, WBS is not flowing for a Material in delivery, in turn WBS is not flowing in Billing document for same material, in turn not allowing to Post the Billing document to Accounting.
    Error while releasing Billing to the Accounting: Accounting Entry is not generated. Error Message:Assign Condition type
    YMRG in COPA.
    Pls let me know, what can be the reason ?
    Thanks.
    Amit.

    Hi Kuldeep,
    Check this note,
    Note 159387 - Message BP603: incorrect line item is displayed
    Its valid only till 4.6. Might give you some idea but.
    Regards,
    Gokul

  • I recently backed up my iPad and then I restored it to factory settings. Now, I want to restore it from the back up that I created, but it will not accept my Apple ID password. Is there any way that I can save my data?

    Hi,
    As I have said in the title, I was supposed to do a restore on my iPad for work. I backed up the device and then I restored it to factory settings as I was instructed. Now that all of that is complete, I tried to restore it from the back up point I created and it will not recognize my Apple ID password.  I really hope that I won't lose all of my data, but I don't know what else to do. I have tried entering my password numerous times. I really hope that someone can help me.

    Restoring an iPad from an iTunes-generated backup should not require an Apple ID password.
    Did you encrypt the iPad backup? If so, then trying to restore will require entering the encryption password.

  • Cannot create mysites from powershell: Original XSLT List View Web Part not found

    I have a bizarre problem in my SharePoint 2013 farm. This does not occur in my test farm, only in the farm we were going to go live with.
    I'm on windows Server 2012, SQLServer 2012 SP1, SharePoint 2013 April CU. 1 appserver/centraladmin server, 2 web servers.
    When I log into our mysitehost and click newsfeed, it will create a mysite (even though first it displays "we are sorry there was a problem creating your site")
    But from powershell, whether I use $UserProfile.CreatePersonalSite() or New-SPSite, I get the following error:
    Original XSLT List View Web Part not found
    So far I've only found one other person with this:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2503e42c-e114-4e89-8e00-89fe70f0b154/cannot-create-sharepoint-mysite-programmatically
    This is a brand new farm, created with the same scripts I created my test farm with, and same version of SharePoint. Only the service accounts are different. (Farm account has admin on the servers right now since I was setting up profile service).
    Some other errors from the same correlation ID that look related:
    It can't seem to find the listemplate 101
    And something looks wrong with the MySiteDocumentLibrary feature
    I have tried the following:
    1. run psconfig.exe on each server
    2. install-spfeature -AllExistingFeatures
    3. looped through the directory under Features and for each called Install-SPFeature $dirname -Force
    4. uninstalled and reinstalled MySiteDocumentLibrary feature
    5. blew away the whole farm (removed all servers from farm, deleted all databases) and recreated it.
    6. tried creating the UPA from the CentralAdmin gui.
    The only real difference I can think of between the working farm and non working farm is, I installed the working farm using RTM, then as they came out added the March PU and April CU. For this farm I installed RTM and March and April, and then ran my build
    farm script.
    I am at a loss. What do I need to do, re-install the binaries? That's all I can think of. What I love is that our test / POC system worked fine, and now 2 weeks before go-live I'm seeing errors on the production servers I've never seen before. Using the
    same scripts no less.
    Feature Activation: Feature 'Fields' (ID: 'ca7bd552-10b1-4563-85b9-5ed1d39c962a') was activated
    Feature Activation: Feature 'CTypes' (ID: '695b6570-a48b-4a8e-8ea5-26ea7fc1d162') was activated
    No document templates uploaded for list "$Resources:core,global_onet_solutiongallery_list;" -- none found for list template "100"
    Failed to find <ListTemplate> tag corresponding to ID "101", tried both onet.xml for site definition ID "0" language "1033" and global site definition. Operation failed.
    No document templates uploaded for list "$Resources:core,stylelibraryList;" -- none found for list template "121".
    System.Runtime.InteropServices.COMException: A user may not remove his or her own account from a site collection.<nativehr>0x81020051</nativehr><nativestack></nativestack>, StackTrace: at Microsoft.SharePoint.SPUserCollection.UpdateMembers
    Feature Activation: Feature 'MySitePersonalSite' (ID: 'f661430e-c155-438e-a7c6-c68648f1b119') was activated
    Feature Activation: Activating Feature 'MySiteDocumentLibrary'
    Calling 'FeatureActivated' method of SPFeatureReceiver for Feature 'MySiteDocumentLibrary'
    SharePoint Foundation Upgrade MySiteDocumentLibraryFeatureReceiveraj08n INFO Creating new My Documents library
    Unknown SPRequest error occurred. More information: 0x80070002
    SPRequest.GetMetadataForUrl: UserPrincipalName=, AppPrincipalName= ,bstrUrl=http://contoso/personal/cbuchholz/DOCUMENTS ,METADATAFLAGS=59
    System.IO.FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>, StackTrace: at Microsoft.SharePoint.SPWeb.GetObjectForUrl at Microsoft.SharePoint.Portal.UserProfiles.MySiteDocumentLibraryUtil.GetSPObjectFromUrl ...
    <nativehr>0x80070002</nativehr><nativestack></nativestack>There is no Web named "/personal/cbuchholz/DOCUMENTS"
    Possible mismatch between the reported error with code = 0x81070504 and message: "There is no Web named "/personal/cbuchholz/DOCUMENTS"." and the returned error with code 0x80070002.
    Attemping to add webpart id 0F6072F2-E804-4CFD-837E-BB37332B9D1C to web http://contoso/personal/cbuchholz
    Adding XsltListViewWebPart calling SPRequest::CreateListViewPart. Web part id 0F6072F2-E804-4CFD-837E-BB37332B9D1C, web http://contoso/personal/cbuchholz
    Feature receiver assembly 'Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c', class 'Microsoft.SharePoint.Portal.UserProfiles.MySiteDocumentLibraryFeatureReceiver', method 'FeatureActivated' for feature 'e9c0ff81-d821-4771-8b4c-246aa7e5e9eb' threw an exception: System.InvalidOperationException: Original XSLT List View Web Part not found at Microsoft.SharePoint.Portal.UserProfiles.MySiteDocumentLibraryUtil.ReplaceListViewWebPart
    Feature Activation: Threw an exception, attempting to roll back. Feature 'MySiteDocumentLibrary'
    Exception in EnsureFeaturesActivatedAtSite: System.InvalidOperationException: Original XSLT List View Web Part not found
    Failed to activate site-collection-scoped features for template 'SPSPERS#2' in site collection 'http://contoso/personal/cbuchholz'
    Failed to apply template "SPSPERS#2" to web at URL "http://contoso/personal/cbuchholz
    I've had other problems in this farm: the bug where when you add Administrators to a Search Service via the Manage Service Applications page, it removes the SPSearchDBAdmin role from the search service process account. That one did not happen in the other farm.
    At least other people have that one and I could just use the farm admin instead (still troublng of course).

    Ok,
    Here is the problem:
    When creating a mysite from powershell or script, apparently you can ONLY do this from a wfe (or a server running Microsoft SharePoint Foundation Web Application in services on server).
    You CANNOT create mysites from script on your appserver if it is not also a Web Application Server. I confirmed the same is true in my test farm. I guess I was always running most of these scripts on the webserver.
    I searched all over and cannot find this documented anywhere.
    Who do I contact to have Microsoft document this?
    It's Thursday morning, I've been working non stop since Saturday morning so you don't have to :)

  • "Create links from URLs" preference no longer working in sticky notes

    I work with reading other people's sticky notes in Adobe Acrobat X Pro (now version 10.1.1). When they wrote URLs in the sticky notes it used to recognize them as links; now they're just plain text. My Preferences > General > "Create links from URLs" option is checked ON. I aso tried View > Tools > Document Processing > "create Links from URLs" and it added two links but only outside of the sticky notes. I am on Windows 7 Professional 64-bit. Thanks.

    AFAIK, URLs inside annotations were never converted into actual links. I'm not even sure it's technically possible to do so.
    It might have happened if the annotations were flattened and the text in them became a part of the static text of the PDF. Then the URLs in it could have been converted into "live" links, but not before.

  • Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Hi connally25,
    Below is a link to a video tutorial on how to add a Facebook Log button, please check if you have followed the same steps to add the video.
    http://tv.adobe.com/watch/learn-adobe-muse-cc/adding-a-facebook-like-button/
    If you have followed the steps correctly and the button still does not work; here is a link to a forum thread which might help solving the issue:
    Facebook Follow Widget not working
    Regards
    Sonam

  • Creating pdf from clipboard does not import images or formatting

    Creating PDF from clipboard works perfect in acrobat X however in acrobat XI no images are imported and the text just defaults to times roman font. My wife uses acrobat for her craft patterns and copies from the web all the time with no issues in Acrobat X. She tried it on Acrobat XI and it just looks like garbage. The text is there but the images that were copied along with the text are not. I have examples that she did using the exact same clipboard in both X and XI.

    Bill@VT wrote:
    I guess I must not understand how you are transferring the items to the clipboard. Is the browser the same one you used with AA X?
    Yes, I used the same browser (Chrome) with AA X and AA XI.
    Bill@VT wrote:
    When I did it with AA XI, I used the mouse (on a PC) to select the text and figures in my browser and copied that info to the clipboard (ctrl-C on the PC and I assume similar on the MAC).
    Yes, the procedure for copying info to the clipboard is similar for a Mac and a PC. I select the info (in this case, text and graphics) with the mouse, and can copy it to the clipboard with either Command-C (Mac equivalent of ctrl-C), or by right-clicking on the highlighted info and choosing "copy" from the pop-up window.  I do not have to use Print Screen in conjunction with this procedure. If I use Print Screen, it copies everything that my monitor displays and the results of a paste are an image.
    Is there something I am missing about getting the web page parts wanted to the clipboard? If you clip the items into a graphics packages, does the graphics show up as desired?
    No, you are not missing anything. All of the web page parts are in the clipboard. The problem is that only the text is showing up when I use the create PDF from clipboard option in AA XI. I do not have a graphics package installed; however, if I paste the clipboard contents into Word, both the text and graphics show up.
    I checked the PDF created with my AA XI and found the text as text and the the graphic as graphic, not simply a graphic as you suggested. Is it possible the graphic is shown with a place holder or just space for the graphic. If that is the case, check the preferences that you have "view large images" turned on.
    As I explained ad nauseum, the PDF I try to create with AA XI using create PDF from clipboard does not include the graphics; it only has the text. I just checked the preferences and "view large images" is turned on. I could not find any other preference settings that would seem to help with the problem I am having.
    I can paste the clipboard contents directly into Word and print the document to a PDF. When I do that, though, I usually have to spend a lot of time editing the Word document, because the contents are not in the same format. The paragraphs are usually squashed together, or the photos are too large and I have to change the size. This just takes up more time than I have to spend.
    The bottom line is that it seems to me Adobe must have changed something in the Mac version of AA XI that causes it to not work the same way it does in AA X. The PC version is obviously okay, because you are able to get the feature to work.
    I guess I am going to have to give up on this problem and stick with using AA X.
    Thanks again for all your help.

  • I'd copied some pictures from a PC to a folder in Finder in my new iMac. The 'Date Created' in iMac is not the same as the 'Date Created' in the PC. Why? Is there a way to fix that?

    I'd copied some pictures from a PC to a folder in Finder in my new iMac. The 'Date Created' in iMac is not the same as the 'Date Created' in the PC. Why? Is there a way to fix that?

    View Menu -> Sort Photos is a good way to start.
    Some organising possibilities in iPhoto:
    I use Events simply as big buckets of Photos: Spring 08, July - Nov 06 are typical Events in my Library. I use keywords and Smart Albums extensively. I title the pics broadly.
    I keyword on a
    Who
    What
    Where basis (The When is in the photos's Exif metadata). I also rate the pics on a 1 - 5 star basis.
    Using this system I can find pretty much find any pic in my 50k library in a couple of seconds.
    So, for example, I have a batch of pics titled 'Seattle 08' and a  typical keywording might include: John, Anne, Landscape, mountain, trees, snow. With a rating included it's so very easy to find the best pics we took at Mount Rainier.
    File -> New Smart Album
    set it to 'All"
    title contains Seattle
    keyword is mountain
    keyword is snow
    rating is 5 stars
    Or, want a chronological album of John from birth to today?
    New Smart Album
    Keyword is John
    Set the View options to Sort By Date Ascending
    Want only the best pics?
    add Rating is greater than 4 stars
    The best thing about this system is that it's dynamic. If I add 50 more pics of John  to the Library tomorrow, as I keyword and rate them they are added to the Smart Album.
    In the end, organisation is about finding the pics. The point is to make locating that pic or batch of pics findable fast. This system works for me.

  • Create PDF From Scanner - Items not tagged by default in Adobe X?

    Our associates leverage Adobe Acrobat's Paper Capture API to create PDFs directly from TWAIN-sourced scanners.  In Adobe Acrobat 9.x, the resulting PDFs were automatically tagged.  In version 10.x they are not, and I don't see a way to enable tagging automatically when using the "File -> Create PDF from Scanner" option.  Strangely, the option to tag the PDF is available when using "File -> Create PDF from Web Page."
    Any ideas?

    Also experiencing this issue.

Maybe you are looking for

  • I can no longer change the volume, anyone know why?

    when i use the volume keys nothing happens. its blocked i cant change it in system preference eather i can mute or have the sound at the loudest. can any one tell me how to fix this?

  • A Ton of Spam / Junk Mail - How to Make it Stop?!

    I'd say over the last two months I'm receiving about 3-4 dozen "spam" messages. When it started I had not done anything particularly "different" on my iMac that would have triggered this. I noticed all the spams are sent from various "mac.com" accoun

  • Will anybody kindly recommend a high end wav to MP3 converter software

    There are so many WAV to MP3 converter software on the market. I tried some of them and was not very happy with them. Will anybody kindly recommend a high end wav to MP3 converter software that they have had a good experience with. I need this softwa

  • BADI or User Exit for Tax on RRB

    Hi We are trying to get our actual expense costs through to SD RRB as Gross rather than Net. Does anyone know if there is a BADI or user exit to achieve this ? Many Thanks Sara

  • Where is my imac installation disc ??

    Hi . Before few days i receive an imac (with intel) processor . Now i need to install via bootcamp windows 7 operating system both with my mac os x operating . The problem is that i need mac os x dvd and i didn't receive it . What must i do ?? Can i