public class PreviewImage extends Object implements Cloneable
The pixel data consists of interleaved RGBA8 pixels in scan line order.
For the red, green and blue pixel components, intensity is proportional to
pow(x/255, 2.2)
where x
is r
, g
or b
.
For alpha 0 is transparent and 255 fully opaque.
The x
and y
coordinates of the pixels data array
go from 0 to w-1
, and from
0 to h-1
respectively; w
corresponds to
getWidth()
and h
to getHeight()
. The pixel with
coordinates (x,y)
is at array index 4*((y*w)+x)
.
Pixel (0,0)
is the upper left corner of the preview image.
Constructor and Description |
---|
PreviewImage(int width,
int height)
Constructs a new preview image with
width by height
pixels initialized with (r=0, b=0, g=0, a=255) . |
PreviewImage(int width,
int height,
byte[] pixels)
Constructs a new preview image with
width by height
pixels initialized with the values from pixels . |
PreviewImage(int width,
int height,
byte[] pixels,
int offset)
Constructs a new preview image with
width by height
pixels initialized with the values from pixels starting at
offset . |
Modifier and Type | Method and Description |
---|---|
PreviewImage |
clone()
Creates and returns a copy of this preview image.
|
boolean |
equals(Object obj)
Compares this preview image to the specified object.
|
int |
getHeight()
Returns the height of this preview image.
|
byte[] |
getPixelData()
Returns a reference to the pixel data array of this preview image.
|
int |
getWidth()
Returns the width of this preview image.
|
int |
hashCode()
Returns a hash code for this preview image.
|
int |
index(int x,
int y)
Returns the index in the pixel data array for the pixel
(x,y) . |
String |
toString()
Returns a string representation of this preview image.
|
public PreviewImage(int width, int height)
width
by height
pixels initialized with (r=0, b=0, g=0, a=255)
.width
- width of the preview imageheight
- height of the preview imageIllegalArgumentException
- if either width
or
height
is negative.public PreviewImage(int width, int height, byte[] pixels)
width
by height
pixels initialized with the values from pixels
.width
- width of the preview imageheight
- height of the preview imagepixels
- initial values for the preview image's pixelsNullPointerException
- if pixels
is nullIllegalArgumentException
- if either width
or
height
is negative, or there is not enough data
in pixels
.public PreviewImage(int width, int height, byte[] pixels, int offset)
width
by height
pixels initialized with the values from pixels
starting at
offset
.width
- width of the preview imageheight
- height of the preview imagepixels
- initial values for the preview image's pixelsoffset
- starting position in pixels
NullPointerException
- if pixels
is nullIllegalArgumentException
- if either width
or
height
is negative, or there is not enough data
in pixels
.public int getWidth()
public int getHeight()
public byte[] getPixelData()
public int index(int x, int y)
(x,y)
.
The index is computed as 4*((y*w)+x)
(each pixel has 4 bytes.)x
- the pixel's x
coordinatey
- the pixel's y
coordinate(x,y)
IndexOutOfBoundsException
- if either parameter is out of rangepublic int hashCode()
PreviewImage
object is computed with its dimensions and the
contents of its pixel data array.public boolean equals(Object obj)
true
if and only if the argument is not null
, is a
PreviewImage
of the same size as this instance, and their pixels
values are all equal.public String toString()
The toString
method for class PreviewImage
returns a string consisting of the prefix "PreviewImage{"
and its dimensions:
"PreviewImage{" + "width=" + width + ", height=" + height + '}'
public PreviewImage clone()