How to convert image to array pixel values in java

I would like to know how to convert image into arrary of pixels in java ?
which API should i use ?
please give me link to a sample program !

I find the most efficient way to just walk over the image and call getRGB(x,y) on every pixel, more so than Pixelgrabber. If someone knows a more efficient way, give me a beep.

Similar Messages

  • How to convert arraylist into array

    how to convert arraylist into array?

    If you are using generics, I would use this version of toArray:
    List < X > list = ...
    X[] array = list.toArray(new X[list.size()]);If you are not using generics, that same thing looks like:
    List  list = ...
    X[] array = (X[]) list.toArray(new X[list.size()]);

  • How to convert dd/mm/yy in ddmmyy in java

    Can any one tell ,how to convert dd/mm/yy in ddmmyy in java

    krishInda wrote:
    Can any one tell ,how to convert dd/mm/yy in ddmmyy in javaI suppose, if you are sure of the validity of the string, you can just rebuild the string without the two forward slashes. Otherwise, see SimpleDateFormat for parsing and formating:
    http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html

  • How to convert numeric data to binary decimal in java

    How to convert numeric data to binary decimal in java Pleas egive me code example

    There is no numeric data. It's all binary. If you're talking about Strings, look at the Integer class.

  • How to convert a 2D array of pixels in to a grayscale planar image

    Im having following problems, I hope someone may help me.
    1.     I want to convert a 2D array of pixels (Grayscale values) into a Grayscale PlannerImage. I tried the following code I found on net.
    The steps to do this are:
    -Construct a DataBuffer from your data array.
    -Construct a SampleModel describing the data layout.
    -Construct a Raster from the DataBuffer and SampleModel. You can use methods from the RasterFactory class to do this.
    -Construct a ColorModel which describes your data. The factory method PlanarImage.createColorModel(sampleModel) will take care of this for some common cases.
    -Construct a TiledImage with the SampleModel and ColorModel.
    -Populate the TiledImage with your data by using the TiledImage.setData() method to copy your raster into the TiledImage.
    Only the last step involves any actual processing. The rest is just object creation.
    public static RenderedImage createRenderedImage(float[][] theData, int width, int height, int numBands) {
    int len = width * height * numBands;
    Point origin = new Point(0,0);
    // create a float sample model
    SampleModel sampleModel =
    RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT,width,height,numBands);
    // create a compatible ColorModel
    ColorModel colourModel = PlanarImage.createColorModel(sampleModel);
    // create a TiledImage using the float SampleModel
    TiledImage tiledImage = new TiledImage(origin,sampleModel,width,height);
    // create a DataBuffer from the float[][] array
    DataBufferFloat dataBuffer = new DataBufferFloat(theData, len);
    // create a Raster
    Raster raster = RasterFactory.createWritableRaster(sampleModel,dataBuffer,origin);
    // set the TiledImage data to that of the Raster
    tiledImage.setData(raster);
    RenderedImageAdapter img = new RenderedImageAdapter((RenderedImage)tiledImage);
    return img;
    I passed it 2D array of pixels with 3 bands, and it gave an exception >>Array index out of bounds at this line >>tiledImage.setData(raster). Then I tried it with a 1D array of length height*width with a single band. So Now it gives me a monochromatic RenderedImage. How can I make it a grayscale PlanarImage.

    jyang, thank you very much for your response. I believe I found a different solution all together, by converting each 16-bit intensity value into an 8-bit intensity value via an intensity ratio (ie: divide each intensity by the maximum and multiply by 256). The attachment shows the new program.
    Attachments:
    mod_image.vi ‏2004 KB

  • Images with negative pixels value

    Consider a simple black (0) and white (255) image composed by 3 vertical bands : the first is white, the second is black and the third is white. Image size is W columns by H lines. Band width is W1, W2, W3 for bands 1, 2 and 3 respectively (W1+W2+W3=W).
    Consider now a first order edge detecting operation, for example Sobel for vertical edges :
    1 0 -1
    2 0 -2
    1 0 -1
    The corresponding edge image is composed of H identical lines (because the image is only varing horizontally). Each line is 0 everywhere, except on transitions : on column W1, there is a positive value of 4*255 and on collumn W1+W2 there is a negative value of -4*255.
    Using the following java source code, we obtain an image which have only the positive (>=0) part of each line :
      Image img = (new ImageIcon("bands.png")).getImage();
      BufferedImage bimg = toBufferedImage(img); // not part of JDK1.4
      ConvolveOp sobel = new ConvolveOp(new Kernel(3,3,new float[]{ 1, 0,-1,2,0,-2,1,0,-1})); // vertical Sobel filter
      BufferedImage bimg_cont = sobel.filter(bimg, null);To have an edge image that contains the negative part of edges, we do need a specific image format with specific ColorModel and SampleModel. Ideally, we will need a grayscale image (1 sample/pixel) where all elements can represent values from -4*255 to 4*255. So we need a signed type like DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT or DataBuffer.TYPE_DOUBLE.
    Note : it is possible to apply the filter twice, with a mirrored filter, but time to compute will be also twice the normal computational time (very inefficient).
    Now, this is the question : do anyone have a solution to compute a sobel filter (or any other filter type which produces negative values) with a resulting image containing positive and negative values ?

    The problem is the size of the number you have to work with. You can store values ranging from 0 to 255 (the max index for a byte-sized variable) so the total numbers you can store is 256. However, if you want to go from -255 to 255, thats about 512 values, which is twice the size of your max. You would need one more bit on that variable to do that. You could make the far left variable be the positive or negative sign (know as a signed variable) which is how computers do it anyway. The only drawback is it will only range from -127 to 127, which is half as much detail.

  • How to convert hex into a string value

    hei evryone!
    can anyone please help me on how to convert a hex value into a string suppose.. Example i want to convert 4275646479 which is a hex value, into a string "BUDDY"? how will i do that???
    Any suggestion, tutorial site would be appreciated?
    Thx!

    something like this will convert string to byte[]
    e.g.
    you want to convert following.
    656667 => ABC
    String toConvert = "656667";
    byte[] returnVal = String2byteArr (toConvert );
    String FinalStr = new String(returnVal);
    public static byte[] String2byteArr(String Result)
    byte[] byteRet = new byte[Result.length()/2];
    int k=0;
    for (int j=0; j<(Result.length()); j+=2)
    try
    Integer I = new Integer (0);
    I = I.decode ("0x"+Result.substring(j, j+2));
    int i = I.intValue ();
    if (i > 127)
    i = i - 256;
    byteRet[k++] = new Integer(i).byteValue();
    catch(Exception e)
    System.err.println(e);
    return byteRet;
    }// String2byteArr
    Hope this will help you, So that i can get 3$ (:-)
    Avi

  • How to convert image to binary format

    Hi all,
      We have developed an Employee search  mobile web application in .net which is hosted on an exposed IP server, we need to show the employee data along with the image of the employee on mobile.
    When we run this application through our desktop we are able to see the image of the employee since we are doing this through <b>intranet</b> , but when we try to access the same from any mobile device we are able to see only the data but no image, since we are doing this through <b>internet(exposed server).</b>
    Please suggest some way to get this image,
    is there any<b> function module in ABAP</b> which can <b>convert image to binary format</b>
    so that we <b>export binary data</b> to .net application

    Hei evryone!
    CAn anyone pls help me on how to solve this error:
    java.security.AccessControlException: access denied (java.security.SecurityPermission insertProvider.SunJCE)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkSecurityAccess(Unknown Source)
         at sun.plugin.security.ActivatorSecurityManager.checkSecurityAccess(Unknown Source)
         at java.security.Security.check(Unknown Source)
         at java.security.Security.insertProviderAt(Unknown Source)
         at java.security.Security.addProvider(Unknown Source)
         at CryptoTest.processFile(SwingApplet.java:68)
         at CryptoTest.<init>(SwingApplet.java:65)
         at SwingApplet.init(SwingApplet.java:39)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Is it allright for a swing code to access local resources? like in my case i want my swing app to decrypt and encrypt an image file but when i tried to access the method for decrypting and encrypting i got this error message on my console. Do i have to make my code signed before i could write/read a file on my hard drive?
    Any help / suggestions would be much appreciated.Thanks!

  • How to convert an int array to string array?

    Hi,
    Can anyone please help me with this question?
    int number={4,6,45,3,2,77};
    I like to convert this into a list and sort
    List mylist = Arrays.asList(number);
    Collections.sort(mylist);
    But first I need to convert the int array to String array.
    Please advise. Thanks.

    If you want to convert your int array to a String array, you have no choice but doing a conversion element by element in a for loop.
    However, if the sort method doesn't behave as desired, you can use the one with 2 parameters, the second parameter being a comparator class.
    Check the javadoc for more information : http://java.sun.com/j2se/1.3/docs/api/java/util/Collections.html
    /Stephane

  • How to convert from xml file to html using java code

    How to convert from xml file to html file using java code

    Get yourself Apache Xalan or Saxon or some XSLT processor
    String styleSheet = "/YourXSLTStylesheet.xsl";
    String dataSource = "/YourXMLDocument.xml";
    InputStream stylesheetSource = TransformMe.class.getResourceAsStream(styleSheet);
    InputStream dataSourceStream = TransformMe.class.getResourceAsStream(dataSource);
    OutputStream transformedOut = new FileOutputStream("filename.html");
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheetSource));
    transformer.transform(new StreamSource(dataSourceStream), new StreamResult(transformedOut));You'll also need to learn XSLT if you don't already know that. Here's a good place to start
    http://www.w3schools.com/xsl/

  • How to convert .doc file into .rtf file in Java?

    Hello All,
    I want to convert doc file into rtf format in java and for the same i am not getting any help so pls suggest some solution for that.
    Thanks and Regards
    only1Vinay

    MS-Word formats (DOC) are notorious for not being standardized from one version to another, so what ever you get will be version specific. If you must do the conversion, I suggest you do a MS-Script in Word to do it or one of the .Net languages. As stated the Word format from version to version is not standardized.

  • How can I convert a 680x480x2 array of values into binary and then joining adjacent elements to make a 640x480 array?

    I am obtaining data from a camera and getting 10-bit data in Labview. I want to convert the element values to binary and then join adjacent elements to create an array half the size of the original. 

    Hi cowboy,
    well 640×480 is not exactly half of 680×480×2...
    - You have to read the specs of your camera. Then you should know how to combine the values.
    - When you get 10bit values you probably need I16 datatype to store the values. Unless you also decrease the color resolution to 8 bit you are still stuck to 640×480×2 byte per image...
    - To join numbers you should have a look at the numerics->data manipulation function palette
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to convert string containing comma seperated values to an array

    my requirement is i have to first convert an comma seperated string to an array
    after that i have to pass the array values to a for loop
    eg:i have a string str=(456,457,487,465,478)
    These values i have to put in an array.
    i then i have to pass the array values to a for loop

    We understand your ¿homeworks? We are helping you, but it seems like you want us to do it.
    Try it yourself with some of the instructions.
    Anyway if there aren´t homeworks, use dinamyc sql:
    declare
    varray := '(45,65,12,4)';
    begin
    execute immediate 'update table set ss=''uu'' where id in ' || varray;
    end;

  • How to convert analog scalar into digital value

    I have the DAQ connected to a system that sends a digital 0 or 1 through the analog BNC connector. If I use DAQ Express VI, I can convert the dynamic data type into a boolean (rather than scalar) array so it's easy to check if the value is 0 or 1. Because I'm running the VI in real-time, I can't use dynamic-to-boolean array conversion. The output I get is a 1-D waveform array which will give me scalar values. The task has a voltage range of -10 to 10 mV. How can I convert that into a 0 or a 1? Should I set the voltage range to 0-5V and simply have an if statement that checks if the value is, let's say, greater than 2.2V (which will mean it's a binary 1)? Is there a better method?
    Thanks. 

    Hi abdel2,
    It sounds like you are trying to measure digital data from your system. If that is the case, you should be able to connect to a digital input line if your DAQ card had them. Then you can set up a digital acquisition in LabVIEW that will interpret the signal as a boolean input.
    If you are not able to do this, you can approximate the digital behavior by reading analog data, and pragmatically determining a threshold (for example 2.2V), though this is a less efficient way to do it.
    Regards,
    Stephen S.
    National Instruments
    Applications Engineering

  • How To Display Image Dimension in Pixels Rather Than Inches

    I am using Photoshop CS3, which I'm still learning to use.  I want to see an open image's dimension (W X H) in pixels in the image's window/workspace.
    Right now, when I open a file it displays the file's Document Sizes in the lower part of the workspace (sorry, don't know the proper terminology).  Selecting the arrow next to this currently displayed information, I can then select Show>Document Dimensions.  However, it always gives the image's width and height dimensions in inches.  But, I want is to see these dimensions in pixels.
    How do I get the document's dimensions to be displayed in pixels rather than inches?  Thanks in advance.

    Oops!  Sorry about putting this in the wrong forum.  I'm using PS to edit images that I'm using within DW.  Hence, my (temporary) confusion.
    Anyway, yes, that solved my problem.  I appreciate the quick response.  Thanks!

Maybe you are looking for

  • :( Second R/3 S/M configuration error in content administrator  :O

    Hi I have a WebAS 640 Java Preview installation.  I have successfully configured two R/3 system in SLD.  But when trying to create the corresponding JCo connections in the content Administrator, it works only for one R/3 system.  It does not even pin

  • ISight with Magnetic mount under TV

    Hi I have a Mac Mini running Snow Leopard and have an external iSight camera attached to it. I have decided to try putting it under the TV attached to the bottom but that means that the camera is upside down is there any way in ichat in 10.6 or some

  • Passing command line unicode argument to Java code

    I have to pass command line argument which is Japanese to Java main method. If I type Unicode characters on command-line window, it displays '?????' which is OK, but the value passed to java program is also '?????'. How do I get the correct value of

  • FLV size

    I uploaded an FLV file. When I click on the 'Play Video' link in the presentation, the FLV opens in a tiny window and the viewer must resize the window. I think the video looks best at 100% (480x360 for my video). I'd like for the window to automatic

  • Ant tasks - real build?

    I've got the WLS Ant tasks (e.g., clientgen) working when I use the examples, but now I want to actually run the WLS Ant tasks from our real Ant build. What do I have to do to do this? I tried sticking webservices.jar and even webservicesclient.jar i