Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Convert a table BufferedImage

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2010
Member
 
Join Date: Dec 2009
Posts: 213
Convert a table BufferedImage
  

Hello,
I would like to know how to convert a table with each cell contains the value of a pixel between 0 to 255 in a BufferedImage?

I have tried the following code, but it does not work
Code:
bufedImage buf = new bufedImage(width, height, bufedImage.TYPE_BYTE_GRAY) ;
buf.setRGB(0, 0, Width, height, pixels, 0, Width) ;
If you have a solution for this then please do post back I am the interested on here. Thanks in advance.

Reply With Quote
  #2  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Convert a table BufferedImage

Hello,
Have you tries with setPixel void (int x, int y, int [] t) in the case of an image of gray. t contains only 1 row and one column contention the pixel value. x and y respectively indicates the line you column of pixels. I think you should try with the following, this will definitely give you an idea about it. If you need any more help regarding this topic then do post back and we will try to help you.
Reply With Quote
  #3  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Convert a table BufferedImage

Hello,
Have a look at the following code, please see if this works for you
Code:
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int c = 0;
for( int i = 0; I <width; i + +)
{
   for(int j = 0J <height; j + +){
     picture.getRaster().setPixel(i, j, new int[1]{c});
}
c + +;
}
Reply With Quote
  #4  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 518
Re: Convert a table BufferedImage

Hello,
Besides the proposed solution, what does not work exactly? Did you try to convert your picture to gray pixels in RGB pixel array before calling the method?
Code:
int[] colors = new int[pixels.length];
for (int i = 0 ; I <pixels.length ; I + +) {
  colors[i] = ((pixels[i] & 0xFF) << 16) | ((pixels[i] & 0xFF) << 8) | ((pixels[i] & 0xFF) << 0);
}
buffer.setRGB(0, 0, Width, height, colors, 0, Width) ;
Obviously, this way, It will use more memory than the method suggested and is probably not preferable. Note, however, direct access to Raster a BufferedImage removes any potential graphics accelaration.
Reply With Quote
  #5  
Old 05-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Convert a table BufferedImage

Hello,
This code is going to help you, take a look at it
Code:
public class buffimgConverter {

  // default version of crbufimg
  static public buffimg crbufimg(Image imageIn,
      Component comp) {
    return crbufimg(imageIn, buffimg.TYPE_INT_ARGB, comp);
  }

  static public buffimg crbufimg(Image imageIn,
      int imageType, Component comp) {
    MediaTracker med = new MediaTracker(comp);
    med.addImage(imageIn, 0);
    try {
      med.waitForID(0);
    } catch (InterruptedException ie) {
    }
    buffimg buffimgo = new buffimg(imageIn
        .getWidth(null), imageIn.getHeight(null), imageType);
    Graphics g = buffimgo.getGraphics();
    g.drawImage(imageIn, 0, 0, null);

    return buffimgo;
  }
}
Reply With Quote
  #6  
Old 05-03-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: Convert a table BufferedImage

Hello,
I am new to the swing components in java, but you can try the following
Code:
javax.swing.JFrame f;                  // Initialized elsewhere

// Create an image, and wait for it to load
Image img = javax.swing.ImageIcon("myimage.gif").getImage();

// Create a BufferedImage of the same size as the Image
BufferedImage buff = (BufferedImage)f.createImage(img.getWidth(f),img.getHeight(f));



Graphics2D g = buff.createGraphics();    // Get a Graphics2D object
g.drawImage(img, 0, 0, f);      // Draw the Image data into the BufferedImage
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Convert a table BufferedImage"
Thread Thread Starter Forum Replies Last Post
Unable to work with table columns in opera browser when the table has wide layout Janya Technology & Internet 5 27-08-2011 10:53 AM
Link a Table to another Table to Drop Down In Main Table himeshRES Windows Software 6 11-12-2010 01:01 PM
To convert a pivot table to a flattened table in MS Excel zeemga Windows Software 3 27-11-2010 05:48 AM
How can I convert text data into table format? Ram Bharose Windows Software 7 30-12-2009 01:58 PM
Convert Excel data to HTML Table Chalina Software Development 2 04-08-2009 11:21 PM


All times are GMT +5.5. The time now is 12:41 AM.