igede

Untitled

Dec 10th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.image.*;
  3. import javax.swing.*;
  4.  
  5. /**
  6.  * OFImage is a class that defines an image in OF (Objects First) format.
  7.  *
  8.  * @author  Gede
  9.  * @version (10/12/2018)
  10.  */
  11. public class OFImage extends BufferedImage
  12. {
  13.     /**
  14.      * Create an OFImage copied from a BufferedImage.
  15.      * @param image The image to copy.
  16.      */
  17.     public OFImage(BufferedImage image)
  18.     {
  19.          super(image.getColorModel(), image.copyData(null),
  20.                image.isAlphaPremultiplied(), null);
  21.     }
  22.  
  23.     /**
  24.      * Create an OFImage with specified size and unspecified content.
  25.      * @param width The width of the image.
  26.      * @param height The height of the image.
  27.      */
  28.     public OFImage(int width, int height)
  29.     {
  30.         super(width, height, TYPE_INT_RGB);
  31.     }
  32.  
  33.     /**
  34.      * Set a given pixel of this image to a specified color. The
  35.      * color is represented as an (r,g,b) value.
  36.      * @param x The x position of the pixel.
  37.      * @param y The y position of the pixel.
  38.      * @param col The color of the pixel.
  39.      */
  40.     public void setPixel(int x, int y, Color col)
  41.     {
  42.         int pixel = col.getRGB();
  43.         setRGB(x, y, pixel);
  44.     }
  45.    
  46.     /**
  47.      * Get the color value at a specified pixel position.
  48.      * @param x The x position of the pixel.
  49.      * @param y The y position of the pixel.
  50.      * @return The color of the pixel at the given position.
  51.      */
  52.     public Color getPixel(int x, int y)
  53.     {
  54.         int pixel = getRGB(x, y);
  55.         return new Color(pixel);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment