1 Image

Class Ax.image.Image


This class contains convenience methods for locating ImageReaders and ImageWriters, and performing simple encoding and decoding. SEE: https://github.com/rkalla/imgscalr/blob/master/src/main/java/org/imgscalr/Scalr.java

Constructor Summary

Method
Description
JSImage(Object object)
Creates a new image, given a source.

Method Summary

Modifier and Type
Method
Description
__resizeImageWithHint(BufferedImage originalImage, int type)
byte[] 
Returns the image as a byte array.
byte[] 
getBytes(Ax.text.String formatName)
Returns the image as a byte array, with the specified format.
int 
Returns the dominant color of the given image.
Ax.text.String 
Returns the image format.
int 
int 
Returns the image size starage need in bytes
int 
boolean 
isJPEG()
Check if image is JPEG
boolean 
Checks if the image's color model includes an alpha channel meaning is transparent.
Ax.image.Image 
resize(int width)
Resizes the image maintaining its height/width ratio so the longest dimension has the specified size.
Ax.image.Image 
resize(int width,int height)
Resizes the image to the specified height and width.
Ax.image.Image 
rotate(Ax.text.String rotation)
Rotates the image using one of the following operators: CW_90, CW_180, CW_270, FLIP_HORZ, FLIP_VERT
Ax.image.Image 
scale(double scale)
Scales the image using a percent factor.
scale(BufferedImage before, double scale)
Scales an image using the Bilinear method.
Ax.image.Image 
setFormat(Ax.text.String format)
Set the image format we want to write the image.
Ax.image.Image 
setName(Ax.text.String name)
Sets the image name to be used in BLOB conversion.
toBlob()
Converts the image to a BLOB object.
Ax.image.Image 
Reduces the size of the image to an optimum quality

Constructor Detail

Ax.image.Image.JSImage

Ax.image.Image.JSImage(
	object object
						)
Info:
Creates a new image, given a source.
Parameters:
object - image source

Example
Copy
var src = Ax.util.Base64.decode("iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAMAAAD8CC+4AAAArlBMVEUAAAD+yRf/yRb/pAj/kxH+mhb/mRb+mRb+mhb+mRf+mhb/mhf+mhb+mhb+mhb/gwD+mhb+mRf+mRb+mRb+mRT+mhf+owD+mRb+mRb+mRb+mRb/mRb+mRb+mRb/mhb+mRf+mRb+mRb+mRb+mRb/mRb+mRb+mRX+mhb+mxX+mBT+mRb+mRX+mRb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pZlv0s2HR4UeEtUP3TaWZloy9CcIvWcSx3U2GkfZjAz9CUKHPfmI3TBKtx+RoT9F6LUOeax/oGMpI5ChP0Xo8AV/M2vwxjtjCYYjQ3+S0P96Mt/1/vzlRMXCJiBDf5LQoZX6mO25RWPv1GToTxM6BOllis6nIxYxBxn684Tu6FkVzE5r6r7UI2QxAxn6E4UeK4Id2kBodJAqasrQnyp0GFGO7wyQxtgAi4/SzeaxoSsLvNFSjt/4ch/9bqx+zAHugX6u3g8pB4cJU5CejxPh3xaH2NVumZhrZIH0hLw2xkTTzS33tcz837SNMKEz+3K4NBWr+0mV9/Z/VNfHMtQ9SN/Zt5PUhIIACKAN2gkJGYxJHBa2ouKEIjj2/U/m2oXy//I3712hoKAW1VztSa7v+B5osu9TzDW9/gcabrXPdcRzK9B4PynmymaHQBHGk1zNZ8dSK8d1EytEvtDsZRmPfvMzcblzSS5P6zLvPkr8ZfsXKNShP5x+5DvdZbq0A2XrrQed/jml9HZa7K5fAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAODGHhwIAAAAAAD5vzaCqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq0BwcCAAAAAIL8rQe5AgAAAAAAHgKWYe6TlvpEzwAAAABJRU5ErkJggg==");
 var img = new Ax.image.Image(src);
 //or
 var image = new Ax.image.Image("file:photo1.jpg");

Method Detail

Ax.image.Image.__resizeImageWithHint

object Ax.image.Image.__resizeImageWithHint(
	object originalImage,
	smallint type
)
Parameters:
originalImage - 
type - 
Returns:
object

Ax.image.Image.getBytes

byte[] Ax.image.Image.getBytes()
Info:
Returns the image as a byte array.
Returns:
byte[]

Ax.image.Image.getBytes

byte[] Ax.image.Image.getBytes(
	string formatName
)
Info:
Returns the image as a byte array, with the specified format.
Parameters:
formatName - the image format
Returns:
byte[]

Ax.image.Image.getDominantColor

smallint Ax.image.Image.getDominantColor()
Info:
Returns the dominant color of the given image.
Returns:
smallint

Ax.image.Image.getFormat

string Ax.image.Image.getFormat()
Info:
Returns the image format.
Returns:
string

Ax.image.Image.getHeight

smallint Ax.image.Image.getHeight()
Returns:
smallint

Ax.image.Image.getSize

smallint Ax.image.Image.getSize()
Info:
Returns the image size starage need in bytes
Returns:
smallint

Ax.image.Image.getWidth

smallint Ax.image.Image.getWidth()
Returns:
smallint

Ax.image.Image.isJPEG

boolean Ax.image.Image.isJPEG()
Info:
Check if image is JPEG
Returns:
boolean

Example
Copy
if (image.isJPEG()) {
 		image.setFormat("jpeg");
 		// This will be jpeg
 		image.getBytes();
  }

Ax.image.Image.isTransparent

boolean Ax.image.Image.isTransparent()
Info:
Checks if the image's color model includes an alpha channel meaning is transparent.
Returns:
boolean

Ax.image.Image.resize

object Ax.image.Image.resize(
	smallint width
)
Info:
Resizes the image maintaining its height/width ratio so the longest dimension has the specified size.
Parameters:
width - size of the longest dimension (width, height), in pixels
Returns:
object

Ax.image.Image.resize

object Ax.image.Image.resize(
	smallint width,
	smallint height
)
Info:
Resizes the image to the specified height and width.
Parameters:
width - width of the image in pixels
height - height of the image in pixels
Returns:
object

Ax.image.Image.rotate

object Ax.image.Image.rotate(
	string rotation
)
Info:
Rotates the image using one of the following operators: CW_90, CW_180, CW_270, FLIP_HORZ, FLIP_VERT
Parameters:
rotation - rotation operator: CW_90, CW_180, CW_270, FLIP_HORZ.
Returns:
object

Ax.image.Image.scale

object Ax.image.Image.scale(
	double scale
)
Info:
Scales the image using a percent factor.
Parameters:
scale - a percent factor to scale, like 2 or 0.5
Returns:
object

Ax.image.Image.scale

object Ax.image.Image.scale(
	object before,
	double scale
)
Info:
Scales an image using the Bilinear method. SEE: https://stackoverflow.com/questions/4216123/how-to-scale-a-bufferedimage AffineTransformOp.filter(), used in scaleBilinear(), is faster than the standard drawing method of Graphics2D.drawImage() in scale2(). Also BiCubic interpolation is the slowest, but gives the best results when expanding the image. (For performance, it should only be compared with scaleBilinear() and scaleNearest().) Bilinear seems to be better for shrinking the image, although it's a tough call. And NearestNeighbor is the fastest, with the worst results. Bilinear seems to be the best compromise between speed and quality. The Image.getScaledInstance(), called in the questionable() method, performed very poorly, and returned the same low quality as NearestNeighbor. Must be public cause is used in ESCPOS
Parameters:
before - original image
scale - a percent factor to scale, like 2 or 0.5
Returns:
object

Ax.image.Image.setFormat

object Ax.image.Image.setFormat(
	string format
)
Info:
Set the image format we want to write the image.
Parameters:
format - 
Returns:
object

Ax.image.Image.setName

object Ax.image.Image.setName(
	string name
)
Info:
Sets the image name to be used in BLOB conversion.
Parameters:
name - the image name to be used in BLOB conversion
Returns:
object

Ax.image.Image.toBlob

object Ax.image.Image.toBlob()
Info:
Converts the image to a BLOB object.
Returns:
object

Ax.image.Image.toOptimumQuality

object Ax.image.Image.toOptimumQuality()
Info:
Reduces the size of the image to an optimum quality
Returns:
object