Convert Image into matrix

I need to know how to convert a black and white image into a matrix form.
I have loaded a file using BuffredImage class.
But dont know how to get the matrix form..
Somebody help me out with the code please.........

Have you looked at the BufferedImage API? If not, you may find some methods there that can help.

Similar Messages

  • How can i convert image into pdf  file

    Hi Friends,
    I want to convert image file(i.e. jpeg,bmp,gif) into pdf file using java apis OR is there any tool which can convert it & which we can integrate into our java application
    Thanks in adva.

    Is there any solution to this case.....?

  • Converting image into byte array

    Hi all,
    How to convert an integer array image into byte array ?
    here i have a image like this :
    private static int pixelArray[] = {
    0xff000000, 0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0xff000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
    From this one i create image like this one :
    Image image = Image.createRGBImage(pixelArray, width, height, true);
    Now i want to convert that pixelArray into byte array ? how to do this
    additionally i want to send this byte array to servlet .
    thanks in advance.

    Hi,
    If you want to convert your int array to a byte array you should
    split each integer into 4 bytes to avoid losing information. You can
    rebuild your integer array later if you need to. I think this code
    will work (i havent tested it):
    byte[] pixel= new byte[pixelArray.length<< 2];
    for (int i= pixelArray.length- 1; i>= 0; i--) {
      int aux= i<< 2;  // i* 4 = i<< 2
      pixel[aux]=    (byte) (pixelArray>> 32);
    pixel[aux+ 1]= (byte) (pixelArray[i]>>> 16);
    pixel[aux+ 2]= (byte) (pixelArray[i]>>> 8);
    pixel[aux+ 3]= (byte) pixelArray[i];
    Greets.

  • Convert image into TIFF 4

    I have a requirement to convert images from TIFF 6 to TIFF 4. I have been able to convert to TIFF without compression. However, to reduce the file sizes I need to implement compression_group4. Although it is listed as being supported . . . it does not appear to be.
    Any ideas?

    (1) Are you using compression? I can create TIFFs but not compress them using .COMPRESSION_GROUP4
    (2) When I try and use JAI's ImageCodec (specifically TIFFEncodeParam) and specify COMPRESSION_GROUP4 I get a run-time error: "java.lang.Error: Unsupported compression scheme specified."
    (3) This error seems to be generated by the line .setCompression, as I have been able to generate the error without specifying an image. (ie: it's not related to this image not being supported)
    (A) Here is the code I'm using:
    OutputStream os = new FileOutputStream(destinationFile); //where destinationFile is a File object representing the saved file
    TIFFEncodeParam param = new TIFFEncodeParam();
    param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
    ImageEncoder enc = ImageCodec.createImageEncoder("TIFF", os, param);
    enc.encode(src); //where src is a RenderedImage Object
    os.close();
    any ideas?
    Thanks in advance!

  • Help regarding converting images into blocks of 8X8

    Hi,
    Please could anyone help me with the source code for converting an image(of any type) into blocks of size 8X8.
    I need these blocks as an input for DCT conversion for Watermarking the image
    Thanks in advance

    Hello
    You can migrate a SAPscript form into a Smart Form and convert a SAPscript style into a Smart Style.
    When converting a SAPscript style into a Smart Style, the system converts all paragraph and character formats with all their properties and attributes without any changes. Thus you can use the converted Smart Style without making any adaptations.
    When migrating a SAPscript form into a Smart Form, the system executes the following steps:
    It copies the language attributes and the output options.
    It migrates the layout information including pages, windows, and their attributes and positions on the page.
    It copies the texts in the form.
    It displays the fields (SAPscript notation: program symbols) in the texts.
    It converts the SAPscript commands (such as NEW-PAGE or IFu2026ENDIF) to comment lines and displays them in the texts.
    After the migration, you have a template that you can enhance and modify according to your needs. Adapt the form logic by specifying the commands which the system converted to comment lines.
    Refer to URL for more details - http://help.sap.com/saphelp_nw04/helpdata/en/9d/9599386185c064e10000009b38f8cf/content.htm
    Regards.

  • Convert image into dots

    How can I create a fade (for my purposes, from black to white) using identically sized individual dots? I don't want halftone, because the size of the dots varies. I want a fade, starting from 100% concentration (black, with no space) to 0% concentration (no dots). Anyone know how to do this? Thanks!

    Make a gradient and use the Color Halftone filter on it. Convert to grayscale first because you only want the black dots, and change the screen angle to 90 degrees.
    Use as overlay, or as a mask:

  • 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.

  • Preserving alpha while converting images to grayscale

    I am trying to convert images into grayscale.
    I use this code
    public static BufferedImage grayScale(BufferedImage im) {
            BufferedImage image = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
            Graphics g = image.getGraphics();
            g.drawImage(im, 0, 0, null);
            g.dispose();
            return image;
        }but transparent parts become black. Is there a simple way to preserve opacity while converting to grayscale.

    Since you want to preserve the alpha channel you'll need to get and set the pixels yourself. And you'll have to use a BufferedImage type that
    supports an alpha channel. TYPE_BYTE_GRAY won't do...
    public static BufferedImage grayScale(BufferedImage im) {
         BufferedImage grayImage = new BufferedImage(im.getWidth(), im.getHeith(), BufferedImage.TYPE_INT_ARGB);
         for(int x = 0; x < im.getWidth(); x++)
              for(int y = 0; y < im.getHeight(); y++){
                   int argb = im.getRGB(x,y);
                   int a = (argb >> 24) & 0xff;
                   int r = (argb >> 16) & 0xff;
                   int g = (argb >>  8) & 0xff;
                   int b = (argb      ) & 0xff;
                   int l= (int) (.299 * r + .587 * g + .114 * b) //luminance
                   grayImage.setRGB(x,y, (a << 24) + (l << 16) + (l << 8) + l);
         return grayImage;
    }

  • Load a redrawn image into a JLabel and save it into a BufferedImage?

    Hello, I'm doing a small application to rotate an image, it works, but I'd like to show it into a JLabel that I added, and also store the converted image into a BufferedImage to save it into a database, this is what I have so far:
    public void getImage() {
    try{
    db_connection connect = new db_connection();
    Connection conn = connect.getConnection();
    Statement stmt = conn.createStatement();
    sql = "SELECT image " +
    "FROM image_upload " +
    "WHERE image_id = 1";
    rset = stmt.executeQuery(sql);
    if(rset.next()){
    img1 = rset.getBinaryStream(1);
    buffImage = ImageIO.read(img1);
    rset.close();
    } catch(Exception e){
    System.out.println(e);
    public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    ImageIcon imgIcon = new ImageIcon(buffImage);
    AffineTransform tx = AffineTransform.getRotateInstance(rotacion, imgIcon.getIconWidth()/2, imgIcon.getIconHeight()/2);
    g2.drawImage(imgIcon.getImage(), tx, this);
    jLabel1.setIcon(imgIcon);
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    setRotacion(getRotacion() + 1.5707963249999999);
    repaint();
    I get the image from a db, then using the paint() method I rotate the image, it works, but the new image is outside of the JLabel and I don't know how to assign the new one into the JLabel (like overwritting the original) and also how to store the new image into a BufferedImage to upload it into the database converted, thanks in advanced, any help would be appreciated, thanks!!
    Edited by: saman0suke on 25-dic-2011 14:07
    Edited by: saman0suke on 25-dic-2011 15:08

    I was able already to fill the JLabel with the modified content, just by creating a new BufferedImage, then create this one into a Graphics2D object and the drawing the image into it, last part, inserting the modified image into the database, so far, so good, thanks!
    EDIT: Ok, basic functionality is ok, I can rotate the image using AffineTransform class, and I can save it to the database and being displayed into a JLabel, now, there's a problem, the image for this example is 200 width and 184 height, but when I rotate it the width can be 184 and the height 200 depending on the position, but the BufferedImage that I create always read from original saved image:
    bimage = new BufferedImage(buffImage.getWidth(), buffImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Is there a way that I can tell BufferedImage new width and height after rotate it? :( as far as I understand this cannot be done because before the image bein rotated the bufferedImage is already created and, even being able to do it how can I get width and height from rotated image? thanks!
    Edited by: saman0suke on 25-dic-2011 19:40

  • How do I stop FireFox from converting css3 transforms such as scale, or rotate, into matrix transforms?

    Go to pilatch.com/cards and click any of the cards in the arc. Now do the same in Chrome, or Safari, or IE 9. I have un-min-catted all my JavaScript, so you can see what's going on more easily.
    CSS3 transforms in version 16 of FireFox are being converted into matrix transforms.
    It pretty much horks my rotate and scale animations.
    For instance, if you set the style attribute of an element to something like, style="transform:scale(0.75)", FireFox immediately converts that element's transform property, such as <element>.style.transform to "matrix(...)".
    I know how to do the linear algebra to convert rotate and scale via jQuery cssHooks into matrix transformations, and I've even written code to detect this "feature" of a browser, (that it forces a transform into matrix), and return a different hook that writes a matrix transform instead of a rotate transform, or scale, all in the past two days, on my development site.
    However, it's proving to be increasingly challenging to make this new feature compatible with jQuery's animations. Going further, I may have to hack jQuery just to make this work for FireFox, or drop FireFox animation support altogether unless some FireFox developers make their new implementation backwards compatible.
    I know that transforms normally get converted into matrices behind the scenes in the rendering engine. Leave your matrix there. Don't overwrite what the user has put in for a transform!
    I also know that I should be using CSS3 animations, but, dangit, I started this project before those had widespread support. I can't rewrite all my animations because I want to support FireFox. That's not really an option. I'll direct my users to Chrome instead. I have more features in development that use these types of animation, and I'm in too deep to turn back.
    Thanks for your consideration. Please contact me as you learn more about this.
    -Beefzilla

    The URL in question is [http://pilatch.com/cards pilatch.com/cards]

  • How can i convert an image into gif file as jpeg by using com.sun.image.*

    please help me to convert an image into gif format. i have used sun's impl com.sun.image.code.jpeg package to convert a buffered image into a jpeg file. is there any implementatioln available from sun to handle gif files.

    Many. Try for instance google with 'java image encoders'. Go to the URL http://www.google.com/search?q=java+image+encoders and be amazed of the wonders of modern web search tools.

  • Photoshop CC 2014 - Stack Mode Disabled - Load Image Into Stack Has No "Convert To Smart Object" Option

    Hi,
    I have just installed Photoshop CC 2014.1 and I have "Stack Mode" command disabled.
    Also, I have no option to convert layers into smart object  when I run "Load Image Into Stack" command.
    Can you please tell me how to enable these features?
    Thank you very much.
    Luca

    The 512 MB are a minimum requirement, not some optional thing. Without it, 3D will never work.
    Mylenium

  • Is there any way of converting a jpeg image into a vector in Fireworks? Deity Babbage, where be thee?

    I am hoping for a quick way of converting images (jpeg etc) into a vector.
    Is this possible?
    Thanks
    Eddie

    Try this:
    http://vectormagic.com/home
    It won't work with really complex images or photos, but if you have something like a logo, it can work well. You'll need to edit the vectors it generates to smooth out some bumps and incorrect nodes, but editing a vector is much easier than drawing the whole thing from scratch.
    Hope this helps!

  • How to convert 24bits png image into 8 bits image

    Hi,
    I have gone through some of threads in this forum on changing color bits. But, I still can find right way to change my image (24bits) into different color bits(8 bits). The reason i want to change the color bits because I am getting a GIF image from map server, convert it into PNG format then rescale then into size of mobile phone screen.The PNG image is really has large data length , so the it took a while to load the whole image on screen.
    Note : The following code is taken from few threads in this forum and i have modified it to suit my application.
    I have no idea about Java2d...any help really appreciated...Thanks in advance!!!
    My code is as follow:-
    public File Scale(int width, int height, BufferedImage ImgSrc)
         try
                   //BufferedImage bi = ImageIO.read(ImgSrc);
                   //int w = bi.getWidth(), h = bi.getHeight();
         //Image oldRescale = bi.getScaledInstance(i, j, Image.SCALE_SMOOTH);
         BufferedImage Rescale = rescale(ImgSrc, width, height);
                   //ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
                   //ColorConvertOp op = new ColorConvertOp(cs, null);
                   //Rescale = op.filter(Rescale, null);
         File outfile = new File("map.png");
                   ImageIO.write(Rescale, "png", outfile);
                   BufferedImage fromFile = ImageIO.read(outfile);
                   ColorModel cm = fromFile.getColorModel();
                   System.out.println(cm.getClass() + ", bits/pixel=" + cm.getPixelSize());
              catch(Exception e)
                   e.printStackTrace();
              return new File("map.png");
         public static GraphicsConfiguration getDefaultConfiguration()
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    return gd.getDefaultConfiguration();
         public static BufferedImage copyRescaled(BufferedImage tgt, BufferedImage src)
              Graphics2D g2 = tgt.createGraphics();
    int w=tgt.getWidth(), h=tgt.getHeight();
    hintForBestQuality(g2);
         g2.drawImage(src, 0, 0, w, h, null);
         g2.dispose();
    return tgt;
    public static Graphics2D hintForBestQuality(Graphics2D g2)
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
              RenderingHints.VALUE_RENDER_QUALITY);
    return g2;
         public static BufferedImage rescale(BufferedImage src, int w, int h)
    int transparency = src.getColorModel().getTransparency();
    GraphicsConfiguration gc = getDefaultConfiguration();
    BufferedImage tgt = gc.createCompatibleImage(w, h, transparency);
    return copyRescaled(tgt, src);

    First, we need to be clear about what you're trying to do -- is it rescale an
    image or insure that the image is saved with a 8bit pixel depth? Or both? You are also
    using GraphicsConfiguration's createCompatibleImage, which is excellent if you are going
    to display the image immediately because it might be hardware accelerated
    or compatible with hardware format, but you mentioned mobile phone screens, so
    there is no advantage to using GraphicsConfiguration in that case, and if fact, it's
    probably changing your ColorModel when you're not looking.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class Example {
        public static void main(String[] args) throws IOException {
            URL url = new URL("http://java.sun.com/developer/technicalArticles/GUI/JavaServerFaces/fig2.gif");
            BufferedImage image = ImageIO.read(url);
            System.out.println("image's colormodel = " + image.getColorModel().getClass());
            BufferedImage rescaled = scaleAndConvertColorModel(image, 0.75, null); //GIF => IndexColorModel
            System.out.println("rescaled's colormodel = " + image.getColorModel().getClass());
            File png = new File("junk.png");
            ImageIO.write(rescaled, "png", png);
            BufferedImage fromFile = ImageIO.read(png);
            System.out.println("fromFile's colormodel = " + image.getColorModel().getClass());
            JPanel cp = new JPanel(new GridLayout(0,1));
            addTo(cp, image, "original image");
            addTo(cp, rescaled, "rescaled image");
            addTo(cp, fromFile, "png file image");
            JFrame f = new JFrame("Example");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(cp);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            Will rescale and convert colormodel if necessary.
            ColorModel == null => don't convert. May return src if suitable.
        public static BufferedImage scaleAndConvertColorModel(BufferedImage src, double scale, ColorModel cm) {
            int w0 = src.getWidth();
            int h0 = src.getHeight();
            int w = (int) (w0 * scale);
            int h = (int) (h0 * scale);
            ColorModel cm0 = src.getColorModel();
            if (cm == null)
                cm = cm0;
            if (w==w0 && h==h0 && cm.equals(cm0))
                return src;
            BufferedImage tgt = createImage(w, h, cm);
            Graphics2D g = tgt.createGraphics();
            if (scale < 1) {
                Image temp = src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING);
                g.drawImage(temp, null, null);
            } else {
                hintForBestQuality(g);
                g.drawRenderedImage(src, AffineTransform.getScaleInstance(scale, scale));
            g.dispose();
            return tgt;
        public static BufferedImage createImage(int w, int h, ColorModel cm) {
            if (w <= 0 || h <= 0)
                throw new IllegalArgumentException("...");
            boolean alphaPremultiplied = cm.isAlphaPremultiplied();
            WritableRaster raster = cm.createCompatibleWritableRaster(w, h);
            return new BufferedImage(cm, raster, alphaPremultiplied, null);
        public static Graphics2D hintForBestQuality(Graphics2D g) {
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
            return g;
        static void addTo(Container c, BufferedImage image, String title) {
            JLabel label = new JLabel(new ImageIcon(image));
            label.setBorder(BorderFactory.createTitledBorder(title));
            c.add(label);
    }

  • Using QuickTime Pro to convert a series of JPEG images into a QT movie?

    Can I use QuickTime Pro to convert a series of JPEG images into a QT (uncompressed) movie? Thanks...
      Windows XP  

    Yes.
    One of the features of the QuickTime Pro upgrade is "Open Image Sequence". It imports your sequencially named (1.jpg, 2.jpg) liked sized images (any format that QT understands) and allows you to set a frame rate.
    http://www.apple.com/quicktime/tutorials/slideshow.html
    You can also adjust the frame rate by adding your image .mov file to any audio clip. Simply "copy" (Command-A to select all and then Command-C to copy) and switch to your audio track.
    Select all and "Add to Selection & Scale". Open the Movie Properties window and "Extract" your new (longer or shorter) file and Save As.
    As you've posted in the Mac Discussion pages but your profile says XP you'll need to subsitute Control key where I reference Command key.

Maybe you are looking for

  • F1 help in webdynpro for java

    Hello Exports, I wish to implement F1 help for fields on webdynpro page. Is this possible in webdynpro for Java? Any kind of reference in this regard will be useful. Best regards, Nakul

  • Can't create a folder without being asked for a login password.

    I'm running 10.9.5 on an iMac. When I try to create a folder I'm asked for my login password. When I try to move a file into the folder I'm asked again for my login password. This is very annoying. My other Mac running 10.4.8 doesn't do this.

  • Updated AgentID not displaying correctly on CTIOS SD

    Hi, We've changed an AgentID of one agent. CTIOS Agent Desktop's agentID has been updated but on CTIOS Supervisor Desktop, agentID of that agent is still showing the old agentID. Anyone knows how to refresh the agentID on the CTIOS Supervisor Desktop

  • Load var swf - half working...

    In previous thread we created the random script. Now i want to switch it, to able to load swf's. showing 10 random numbers in the 10 textfield worked fine. Currently after the modification, it only display the last movie number for all the 10 clips.

  • Issue with SOAP.jar in Oracle Apps 11i

    Hi, We have developed OAF page in R11i to call BPEL services, it works fine with following settings 1. Place soap.jar on server from JDeveloper 2. Set class path to point soap.jar in jserv.properties file In our instance one saop.jar already exists i