Performance of BufferedImage.getRGB(int x, int y)

Hi,
My app uses the getRGB method call to extract the RGB values for each pixel contained within an image. This works fine on some images, from the beginning to the end of the process of loading, reading values, and then displaying only taking 2 or 3 seconds.
But this method does have issues with certain images where it can take upto 15 seconds. I'm not certain what causes this because it's not down to the file size or image size itself, as i get an 1556 * 1054 jpeg file (303KB) to open in about 2 seconds where as a certain 800 * 600 jpeg file (152KB) takes upto 15 seconds.
Does anyone have any idea what is causing this slowdown because I can only think that it might be something to do with the compression used but that is only a guess.
Can anyone help ?

I am loading the image in via the ImageIO.read so the image is already in a BufferedImage format, so to read it into a seperate byte array for each colour channel would require me to write my own load methods for all of the supported image types, i don't want to do this.

Similar Messages

  • StringBuffer delete (int start, int end) is too slow - HELP!!

    I've traced a performance problem to one line of code: a StringBuffer "delete (int start, int end)" call.
    My StringBuffer contains a lot of data, maybe 500,000 characters. My code loops, searching for a particular character (the search is fast, btw). When that particular character is found, I want to delete that character plus the characters following it. My code looks something like:
    int pos;
    while ((pos = myStringBuffer.toString().indexOf('~')) != -1)
         myStringBuffer.delete(pos, pos + 3);I'm 100% sure the bottleneck is the delete call. If I change the code to the following, where I've commented out the delete, it loops the same number of times and runs lightning-fast:
    int pos = 0;
    while ((pos = myStringBuffer.toString().indexOf('~', pos)) != -1)
         pos++;The loop, and therefore the delete method, will be executed thousands of times. To give you some idea of the poor performance I'm seeing, the first code (with the delete) takes more than 10 minutes to run, while the second code (without the delete) takes less than one-tenth of one second.
    Any suggestions? Thank you.

    Thanks for all the help! da.futt's solution works perfectly: 65,000 times through the loop in about one-tenth of one second. Problem solved.
    We're still on Java 1.3.1 (large company = slow to upgrade), so I can't even remove toString(). I wonder how many "small" performance problems we have (and are unaware of) that could be addressed by upgrading?
    My first posting here and a positive result. I'm not a Java expert, but neither am I a rookie. I'll be back to try and help others as I've been helped here.
    Thanks again.

  • How to transfer Object int into int[]?

    I create an array:
    int temp[]={};
    After I value data for each temp element, it becomes Object. //Why?
    When I call:
    SaveRGB=mImage.getColorModel().getRGB(temp);
    It tells me found java.land.Object,
    required: int[];

    No problem.
    The following is parts of my code:
    int[] SaveRGB=mImage.getRGB(0,0,(int)mImage.getWidth(), (int)mImage.getHeight(),null,0,(int)mImage.getWidth());
    int[] intSave=mImage.getColorModel().getComponents(SaveRGB, null, 0);
    for (int i=0; i<=intSave.length-3; i+=3)
    if(intSave[i+1]-intSave<4 && intSave[i+2]-intSave[i+1]<4){
    intSave[i]=0;
    intSave[i+1]=0;
    intSave[i+2]=0;}
    else{
    intSave[i]=255;
    intSave[i+1]=255;
    intSave[i+2]=255;}
    SaveRGB=mImage.getColorModel().getDataElements(intSave, 0, null);
    The compiling message is:
    found : java.lang.Object
    required: int[]
    SaveRGB=mImage.getColorModel().getDataElements(intSave, 0, null);

  • My Firefox crashes every time I open it and none of the steps in the database solve the problem. My crash signature is PaintFrame(nsIRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, unsigned int)

    I tried opening it in safe mode and none of the other help tips in the database on firefox crashes when I open it apply to me. I also ran a couple of virus programs to check for any infections and found nothing. I had been having issues with java previous to firefox beginning to crash. So I attempted to uninstall java from my computer but it did not help.
    My crash signature is PaintFrame(nsIRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, unsigned int) and a search of this term on Mozilla Support pulled up no results.
    I'm not terribly knowledgeable with programming so any suggestions would help!

    I read online about a "clean reinstall" of firefox which seems to have worked! They should include direction on this on their page: https://support.mozilla.com/en-US/kb/Firefox+crashes+when+you+open+it

  • Memory leak in String(byte[] bytes, int offset, int length)

    Has anyone run into memory leak problem using this String(byte[] bytes, int offset, int length) class? I am using it to convert byte array to string, and I am showing memory leak using this class. Any idea what is going on?

    Hi,
    If you post in Native methods forum I assume you are using this constructor in the native side.
    Be aware that getting char * from jstring eats memory that you must free before returning from native with env->ReleaseStringUTFChars().
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Question about public void characters(char []ch, int start, int length) thr

    Can anyone tell me how you would keep all the characters from within one pair of tags together each time characters() is called?
    the character() method doesn't read all the character data at once, and i would like to create a buffer of what it has read.
    thank you.

    I recommend using getNodeName and/or/combination
    with
    getNodeValue to get the strings.i have tried using a buffer, and i have got that to work!
    At long last I am seeing the string I would like to see as it is in the xml file!
    thank you for your help
    here is an example of my code:
    private boolean isDescription = false;
    StringBuffer sb = new StringBuffer();
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if(localName.equals("description")) {
              sb = new StringBuffer();
              isDescription = true;
    public void characters(char []ch, int start, int length) throws SAXException {
         if(isDescription == true) {
              String desc = new String(ch, start, length);
              sb.append(desc);
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
         if(localName.equals("description")) {
              isDescription == false;
              System.out.println(sb.toString());
    }

  • How to user bufferedreader.read(char[] cbuf,int off,int len)

    how to user bufferedreader.read(char[] cbuf,int off,int len)?
    can you give me an sample code? i dont understand the use of offset here... thanks!

    The offset simply gives you the ability to read in data starting at some point in the buffer other than the first character.
    If, for example, you are reading from some stream that is being filled slower than you are reading, then you can write a read loop that will fill the buffer with successive reads - the first at character 0, then next offset past the end of the first set of data, etc.

  • Puzzel- Method to optimize int[ ][ ]of int[ ][ ]'s

    I'm righting a class that takes an int[][], initially filled with 0 or null. A rectangular block is added to the int[][] with a value of 1 - 9. Another rectangular block is added to the int[][] with a different value from the first, usually the next int (2). The current setting is
    final static int width = 47;
    final static int height = 3800;
    public int[][] grid = new int[47][3800];
    I have a method addBlock(int blockWidth, int blockHeight) which adds a block to the grid. However it doesn't properly optimize the grid to fit the most efficient number of blocks. It simply adds a block to the top left corner of the grid (where the top left is grid[0][0]) and checks to make sure the next block does not overflow the width bound of 47. If it does it simply places the block at the first available grid where the grid value = 0 and does not overflow the bounds. It doesn't check to make sure that it isn't overriding other blocks, and it doesn't move existing block to make room for new blocks.
    What I am looking for is a way to keep individual blocks together. There could come a situation where two blocks with the same value touch. In this case what would happen?
    Also how do you move blocks once they have been added to the grid?
    Finally, is there an existing algarythm for doing a best fit on a grid of grids?
    Suggestions, other places to look, code, websites to check or any valuable information would be greatly appreciated.
    If needed I could post the existing source, which stacks the grids from the upper left corner and works down. I have a viewer written already which reads in an int[][] and displays it in 9 colors, however I can easily expand the color recognition to as many colors as needed.

    Hi again,
    even if the sequential adding of block will not lead to an optimized layout of the templates on the bolt, we can improve the algorithm given by robert19791 - starting from the top left position of the bolt working towards the right bottom we can say the following:
    The top-left corner of each rectangle is on the right or bottom edge of another rectangle except for the first one added. So, when we search for a position, we will do it along these edges of all the rectangles added before. The test, if it fits in a certain position, can be done with an intersection check with all other already added rectangles, which right or bottom edges are not left or top of the tested position. Ofcourse the rectangle to add must be inside the bolt.
    This will reduce the postions to check and also give a solution for the overlapping problem Robert has mentioned. In those cases where the fit test fails, it should be tested, how large the overlapping area is - if it is not so big, it is perhaps a good idea to shift the rectangle, which would be overlapped otherwise. During such a shift operation the rule of the top-left-corner sitting on the right or bottom edge of another rectangle can be broken, instead the rule is, that an edge is in contact with another rectangle's edge.
    Ok, this for now
    greetings Marsian

  • Can't convert int to int[]    URGENT!

    HI list!
    Here is the code part I have:
    /** Holds the permutated groups which are arrays of integers. */
    Vector v;
    if(arg.length<3) System.exit (0); //Need at least 3 arguments
    elements=new int[arg.length-1]; //Create array to hold elements
    /* Copy the arguments into the element array. */
    for(i=0;i<arg.length-1;i++) elements=Integer.parseInt(arg[i+1]);
    groupsize=Integer.parseInt(arg[0]); //Get the number in each group.
    calc(groupsize,elements.length); //Find out how many permutations there are.
    v=permutate(groupsize,elements); //Do the permutation
    for(i=0;i<v.size();i++) { //Print out the result
    elements=(int[]) v.get(i);
    System.out.println("");
    for(j=0;j<elements.length;j++) System.out.print(elements
    [j]+" ");
    System.out.println("\nTotal permutations = "+v.size());
    and the error I get is:
    Permutate.java:26: Incompatible type for =. Can't convert int to int[]. for(i=0;i<arg.length-1;i++) elements=Integer.parseInt(arg[i+1]);

    elements=(int[]) v.get(i);
    The above statement is illegal. Its not possible to
    use an array type in casting at all.
    Basically you are trying to do a kind of multiple
    casting, which is not possible.
    You might want to store vectors in vector v instead of
    arrays in vector v. Its better to do this.There's nothing wrong with the line
    elements = (int[]) v.get(i);
    assuming the returned object from the vector is in fact an array of int. Even then, it is a runtime exception condition not a compile-time error.
    Using arrays is perfectly valid where you know the size of the array at creation and do not need to resize it during use... The arrays are fast and compact. This is however not a comment on the approach taken in this case but merely an observation that arrays are not always an inferior choice to one of the collection classes.
    Now put up your dukes... ;)

  • Public int indexOf(int ch, int fromIdx) doesn't work for some decimal value

    I have tested two strings below. These two string are identical, except the first string has a char 'ƒ, which has a decimal value of 131. And the second string has a char 'À', which has a decimal value of 192. I am expecting the same output, which is 11, but I got -1 for the test I did using the first string. In the API for public int indexOf(int ch, int fromIndex), values of ch is in the range from 0 to 0xFFFF (inclusive). It is highly appreciated if anyone could provide any insights on why -1 returned when the first string is tested. Thank you in advance.
    String strHasDecimal131 = "Test value ƒ, it has a decimal value of 131";
    String strHasDecimal192 = "Test value À, it has a decimal value of 192";
    int badDecimal = 131;
    int idxBadDecimal = strHasDecimal131.indexOf( badDecimal, 0);
    System.out.println( "index of Bad Decimal: " + idxBadDecimal );
    The output is: index of Bad Decimal -1
    int badDecimal = 192;
    int idxBadDecimal = strHasDecimal192.indexOf( badDecimal, 0);
    System.out.println( "index of Bad Decimal: " + idxBadDecimal );
    The output is: index of Bad Decimal: 11

    Thank you everyone for your inputs. Following are the print statements and the output: for character 'ƒ' and ' À':
    System.out.println((int)'\u0083' + ", " + (int)'\u00C0' + " print decimal value" );
    Output: 131, 192 print decimal value
    System.out.println((char)'\u0083' + ", " + (char)'\u00C0' + " print character value" );
    Output: ?, À print character value
    According to Latin-1 Supplement table, the first char in the output would have the appearance of ƒ, instead it has the appearance of ?
    System.out.println( (int)'ƒ' + ", "+ (int)'À' + " print integer value");
    Output: 402, 192 print integer value
    I also have tried to print out the decimal value of following char: € &#65533; ‚ ƒ „ … † ‡, according to Latin-1 Supplement table, these char has decimal value of 128 through 135 and hex value 0x0080 through 0x0087. And the output from java println is: 8364 65533 8218 8222 8230 402 8224 8225.
    System.out.println((int)'€' + " " + (int)'&#65533;' + " " + (int)'‚' + " " +(int)'„' + " " + (int)'…' + " " +(int)'ƒ' + " " + (int)'†' + " " + (int)'‡' );
    As I did before, I print out character of decimal value of 128 through 135
    System.out.println((char)128 + " " + (char)129 + " " + (char)130 + " " +(char)131 + " " + (char)132 + " " +(char)133 + " " + (char)134 + " " + (char)135 );
    Output: ? ? ? ? ? ? ? ?
    Not sure why java prints character for decimal value of 128 through 159 differently from what appears in the Latin-1 Supplement table. Any of your inputs are appreciately.

  • How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]'_

    Hi,
    I created a structure. It contains 1& 2 diamensional arrays. Now I want to pass values to these arrays. But at that time I got the following error.
        Error 2 Cannot implicitly convert type 'int' to 'int[]' 
            publicstructtest
              [FieldOffset(160)]
             [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 3)]
            publicint[]
    DC;
               [FieldOffset(168)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
              publicfloat[]
    IN;
               [FieldOffset(176)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
            publicbyte[,]
    us;
    privatevoidbutton1_Click(objectsender,
    EventArgse)
    //int[] T_ADC = new int[3];
                array[0].DC =12
                array[0].IN[0] = 11;
                array[0].us[0, 0] = 1;

    @DAANNIII
    >>I wrote the code as follows
    array[0].DC[0]
    =12
    but after that I got an error that  " Object reference not set to an instance of an object".Why this type of error occurs??
    Still confused about how you define variable "array[0]".
    Based on your error information, because your DC is null. As I said before, DC is an int[]. You must assign an array to DC.
    int[] array = new int[] { 2, 43 };
    test s = new test();
    s.DC = array;
    s.DC[0] = 12;//It works fine
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • SetRowHeight(int row,int height) fails

    Hi!
    I have a problem when I want to resize a row to a new height using the method
    setRowHeight(int row,int height)this don't do nothing!
    I'm using the example of a special JTable to merge cells wich is avaiable in http://codeguru.earthweb.com/java/articles/139.shtml
    I try to look in the code of this example, but I can't find the problem.
    I'm not using the merge method in the row I want to resize, so it should be working.
    If someone could help me I appreciate.
    Thanks in advance.

    From what I can tell from looking at the source code for MultiSpanCellTableUI, the paint method draws the cell rects using the general row height (ie table.getRowHeight() ) instead of the row specific height (table.getRowHeight(int row)). This could be a design flaw. You could attempt making the change in source code and see what results you get.
    ICE

  • Driver not support createStatement(int resultSetType, int resultSetConcurrency)

    I am using Weblogic 5.1 for development and would like to use resultset for
    updating
    when I call 'createStatement(int resultSetType, int resultSetConcurrency)'
    Error message prompt out that the driver does not support such method
    I am using weblogic.jdbc20.oci.Driver & weblogic.jdbc.mssqlserver4.Driver
    for testing
    Can some body help me
    regards,
    Fannie

    Right, this method is not implemented by weblogic driver. You should get a
    message like,
    "This JDBC 2.0 method is not implemented" from
    weblogic.jdbc20.oci.Connection or weblogic.jdbc20.mssqlserver4.TdsConnection
    "Fannie" <[email protected]> wrote in message
    news:3b563e73$[email protected]..
    I am using Weblogic 5.1 for development and would like to use resultsetfor
    updating
    when I call 'createStatement(int resultSetType, int resultSetConcurrency)'
    Error message prompt out that the driver does not support such method
    I am using weblogic.jdbc20.oci.Driver & weblogic.jdbc.mssqlserver4.Driver
    for testing
    Can some body help me
    regards,
    Fannie

  • Error message:can't convert int to int[]

    Hi,
    I am trying to build a java code which convert decimal to binary
    but ,I found error message "can not convert int to int[]"
    some line of code:
    int i=12,n=0;
    int arr[n]=i%2;
    n++;
    here I am trying to store remainder in an integer arrary.
    how can i do this???????
    guide me please
    -shobhit singh

    shobhit_onprob wrote:
    i want to store some integer values in to an integer arraryDid you follow the address that was given to you? I doubt it, and even if you did, 2 minutes is not enough time to read, let alone understand, the tutorial.
    Go back there, it describes all the basics you need.

  • Firefox crashes almost constantly. My crash signature is CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int)

    <pre><nowiki>Firefox 4.0.1 Crash Report [@ CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int) ]
    Search Mozilla Support for Help
    ID: df5fa277-41b2-46b3-9f02-2bf3f2110513
    Signature: CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int)
    Details
    Modules
    Raw Dump
    Extensions
    Comments
    Correlations
    Signature CD3DBase::DrawPrimitive(_D3DPRIMITIVETYPE, unsigned int, unsigned int)
    UUID df5fa277-41b2-46b3-9f02-2bf3f2110513
    Uptime 15.2 minutes
    Last Crash 915 seconds (15.2 minutes) before submission
    Install Age 527000 seconds (6.1 days) since version was first installed.
    Install Time 2011-05-07 23:27:42
    Product Firefox
    Version 4.0.1
    Build ID 20110413222027
    Release Channel release
    Branch 2.0
    OS Windows NT
    OS Version 5.1.2600 Service Pack 3
    CPU x86
    CPU Info GenuineIntel family 15 model 2 stepping 9
    Crash Reason EXCEPTION_ACCESS_VIOLATION_WRITE
    Crash Address 0x1
    User Comments
    App Notes AdapterVendorID: 10de, AdapterDeviceID: 02e0, AdapterDriverVersion: 6.14.12.7061
    D3D10 Layers? D3D10 Layers-
    D3D9 Layers? D3D9 Layers+
    Processor Notes
    EMCheckCompatibility True
    Winsock LSP MSAFD Tcpip [TCP/IP] : 2 : 1 : MSAFD Tcpip [UDP/IP] : 2 : 2 : MSAFD Tcpip [RAW/IP] : 2 : 3 : RSVP UDP Service Provider : 6 : 2 : RSVP TCP Service Provider : 6 : 1 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{D18F9393-8A72-4F22-AA8A-FEF9786EC28E}] SEQPACKET 4 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{D18F9393-8A72-4F22-AA8A-FEF9786EC28E}] DATAGRAM 4 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{32E7F2E7-2ED1-4450-8C6B-8DB1B597737D}] SEQPACKET 0 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{32E7F2E7-2ED1-4450-8C6B-8DB1B597737D}] DATAGRAM 0 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{A01D2C7A-0D97-4183-A5B1-A2FB8C008974}] SEQPACKET 1 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{A01D2C7A-0D97-4183-A5B1-A2FB8C008974}] DATAGRAM 1 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{532EB614-3BEA-4AF3-99AE-989D1B273FF9}] SEQPACKET 2 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{532EB614-3BEA-4AF3-99AE-989D1B273FF9}] DATAGRAM 2 : 2 : 2 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{269D4DF2-D033-4CCA-99B4-0EDBAC2A1D21}] SEQPACKET 3 : 2 : 5 : MSAFD NetBIOS [\Device\NetBT_Tcpip_{269D4DF2-D033-4CCA-99B4-0EDBAC2A1D21}] DATAGRAM 3 : 2 : 2 :
    Adapter Vendor ID
    Adapter Device ID
    Bugzilla - Report this Crash
    Crashing Thread
    Frame Module Signature [Expand] Source
    0 @0x2c07502
    1 d3d9.dll CD3DBase::DrawPrimitive
    2 d3d9.dll _allshl
    3 xul.dll mozilla::layers::ImageLayerD3D9::RenderLayer gfx/layers/d3d9/ImageLayerD3D9.cpp:372
    4 xul.dll mozilla::layers::ContainerLayerD3D9::RenderLayer gfx/layers/d3d9/ContainerLayerD3D9.cpp:330</nowiki></pre>

    *https://crash-stats.mozilla.com/report/index/df5fa277-41b2-46b3-9f02-2bf3f2110513
    Try to disable hardware acceleration.
    * Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    If disabling hardware acceleration works then check if there is an update available for your graphics display driver.

Maybe you are looking for

  • Apple ID security question (I was phished!)

    It appears that I was phished after being prompted to enter my Apple ID and password on what appeared to be a legit link from an email to iCloud.  I successfully changed my Apple ID password, but is there anything else I should do?  I also forwarded

  • Contextual Event on row selection in the table

    Hi, My taskflow has just a view activity which queries a view object and displays results as a table. This taskflow is inserted in the main page as a region. I have set up a selection listener on the table, to map to a method in a managed bean. I hav

  • Configuring Oracle Text for 10g

    Hello, Sorry, it this sounds like such a newbie question, but is there is a simple guide to the basic configuration and setup of Oracle Text for 10g? Thank you for your help.

  • XY Graph slow in response

    Hi All, I have 2 XY graphs in my VI and for some reason 1 XY is super slow in response. I have attached my vi here which demonstrates the behavior. There are 2 XY graphs. The one on the top is super slow in response and the one below behaves normally

  • Urgent  javascript function is not being called

    I have the code as below html and jsp and i want the validation to be done before submission of the form can anybody help me how to solve. thanks in advance. regards, srikanth ----(NPV.html code)---- <HTML> <script type="text/javascript" language="ja