3.9K viewsView 14 upvotesView shares Java DIP – Image Pixels
Hire Arvind Upadhyay

Ticker

Java DIP – Image Pixels

An image contains a two dimensional array of pixels. It is actually the value of those pixels that make up an image. Usually an image could be color or grayscale. In Java, the BufferedImage class is used to handle images. You need to call getRGB() method of the BufferedImage class to get the value of the pixel. Getting Pixel Value The pixel value can be received using the following syntax− Color c = new Color(image.getRGB(j, i)); Getting RGB Values The method getRGB() takes the row and column index as a parameter and returns the appropriate pixel. In case of color image, it returns three values which are (Red, Green, Blue). They can be get as follows− c.getRed(); c.getGreen(); c.getBlue(); Getting Width and Height of Image The height and width of the image can be get by calling the getWidth() and getHeight() methods of the BufferedImage class. Its syntax is given below− int width = image.getWidth(); int height = image.getHeight(); Apart from these methods, there are other methods supported in the BufferedImage class. They are described briefly− Sr.No. Method & Description 1 copyData(WritableRaster outRaster) It computes an arbitrary rectangular region of the BufferedImage and copies it into a specified WritableRaster. 2 getColorModel() It returns ColorModel of an image. 3 getData() It returns the image as one large tile. 4 getData(Rectangle rect) It computes and returns an arbitrary region of the BufferedImage. 5 getGraphics() This method returns a Graphics2D, but is here for backwards compatibility. 6 getHeight() It returns the height of the BufferedImage. 7 getMinX() It returns the minimum x coordinate of this BufferedImage. 8 getMinY() It returns the minimum y coordinate of this BufferedImage. 9 getRGB(int x, int y) It returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. 10 getType() It returns the image type. Example The following example demonstrates the use of java BufferedImage class that displays pixels of an image of size (100 x 100)− import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.JFrame; class Pixel { BufferedImage image; int width; int height; public Pixel() { try { File input = new File("blackandwhite.jpg"); image = ImageIO.read(input); width = image.getWidth(); height = image.getHeight(); int count = 0; for(int i=0; i

Post a Comment

0 Comments

Attract Health, Wealth, and Success

Using the Law of Attraction

Are you struggling to become successful, despite having all the knowledge and skills?

It might be because you’re not using the most powerful principle known to mankind.

Join Our Virtual Event!

Available in Hindi and English

Date: 20th Oct 2024

Time: 10 AM to 11 AM

Pay just Rs 50 to join via UPI:

Pay via UPI

Register by emailing: ceoarvindenterprises@gmail.com

Chat with our team on WhatsApp for more information:

917741040321

Register Now Chat on WhatsApp

Event by Arvind Upadhyay.

Arvind Upadhyay is the author of over 100 books, a business and life coach, and famous for his self-help books, high-energy seminars, and workshops.

Join Arvind Upadhyay Succedo Event & Movement

Unlock Your True Potential!

Are you ready to transform your life and achieve the success you deserve?

Join us for an empowering experience!

Event Details:

Date: 25th October 2024

Time: 3 PM to 4 PM

Price/Ticket: Rs 100

Virtual Event

Lifetime Guidance

Pay just Rs 100 to join via UPI:

Pay via UPI

Register by emailing: ceoarvindenterprises@gmail.com

Chat with our team on WhatsApp for more information:

917741040321

Register Now Chat on WhatsApp

Event by Arvind Upadhyay.

Arvind Upadhyay is the author of over 100 books, a business and life coach, and famous for his self-help books, high-energy seminars, and workshops.