Package totalcross.ui.image
Class Image
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.image.Image
-
- Direct Known Subclasses:
ImageTester,MonoImage
public class Image extends GfxSurface
Image is a rectangular image.You can draw into an image and copy an image to a surface using a Graphics object. Images are always 24bpp, and TotalCross supports PNG and JPEG formats at device, and PNG/JPEG/GIF/BMP at desktop (the last two are converted to png when deploying). The deployed png may contain transparency information which is correctly handled.
This is a code sample of how to run a multi-framed image. Note that it will work in the same way in desktop or in device.
Image img = new Image("alligator.gif"); add(new ImageControl(img),LEFT,TOP,FILL,PREFERRED); for (int i = 0; i < 100; i++) { repaintNow(); Vm.sleep(200); img.nextFrame(); }Some transformation methods returns a new instance of this image and other apply to the current instance. To preserve an image with a single frame, usegetFrameInstance(0). Note: TotalCross does not support grayscale PNG with alpha-channel. Convert the image to true-color with alpha-channel and it will work fine (the only backdraw is that the new image will be bigger). The hwScale methods should not be used in images that are shown using transition effects.- See Also:
Graphics
-
-
Field Summary
Fields Modifier and Type Field Description intalphaMaskA global alpha mask to be applied to the whole image when drawing it, ranging from 0 to 255.java.lang.StringcommentA textual description stored in the PNG image.static intFADE_VALUEUsed in getFadedInstance().protected intheightdoublehwScaleHHardware accellerated scaling.doublehwScaleWHardware accellerated scaling.static intNO_TRANSPARENT_COLORDumb field to keep compilation compatibility with TC 1intsurfaceTypeinttransparentColorDumb field to keep compilation compatibility with TC 1booleanuseAlphaDumb field to keep compilation compatibility with TC 1protected intwidth
-
Constructor Summary
Constructors Constructor Description Image(byte[] fullDescription)Parses an image from the given byte array.Image(byte[] fullDescription, int length)Parses an image from the given byte array with the specified length.Image(int width, int height)Creates an image of the specified width and height.Image(java.lang.String path)Loads and constructs an image from a file.Image(Stream s)Loads a BMP, JPEG, GIF or PNG image from a totalcross.io.Stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidapplyChanges()Applies any pending changes made in this image.voidapplyColor(int color)Applies the given color r,g,b values to all pixels of this image, preserving the transparent color and alpha channel, if set.voidapplyColor2(int color)Applies the given color r,g,b values to all pixels of this image, preserving the transparent color and alpha channel, if set.voidapplyFade(int fadeValue)Applies the given fade value to r,g,b of this image while preserving the alpha value.voidchangeColors(int from, int to)Changes all the pixels of the image from one color to the other.voidcreateJpg(Stream s, int quality)Saves this image as a jpeg file to the given stream.
NOT supported on Blackberry.voidcreateJpg4B(Stream s, int quality)voidcreatePng(Stream s)Saves this image as a 24 BPP .png file format (if useAlpha is true, it saves as 32 BPP), to the given stream.booleanequals(java.lang.Object o)Returns true if the given Image object has the same size and RGB pixels of this one.voidfreeTexture()In OpenGL platforms, attempts to free the texture associated with this object, if any.ImagegetAlphaInstance(int delta)Adds the given value to each pixel's alpha-channel of this image.ImagegetClippedInstance(int x, int y, int w, int h)Returns a clipped image from the current position.ImagegetCopy()Gets a copy of this image; if the image is multi-framed, returns a copy of the first frame.intgetCurrentFrame()Returns the current frame in a multi-frame image.ImagegetFadedInstance()Creates a faded instance of this image, decreasing the alpha-channel by 128 for all pixels.ImagegetFadedInstance(int backColor)Deprecated.Use getFadedInstance() insteadintgetFrameCount()Returns the frame count of this image.ImagegetFrameInstance(int frame)In a multi-frame image, returns a copy of the given frame.GraphicsgetGraphics()Returns a new Graphics instance that can be used to drawing in this image.intgetHeight()Returns the height of the image.ImagegetHwScaledInstance(int width, int height)At non OpenGL devices, is the same of getSmoothScaledInstance; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.static ImagegetJpegBestFit(java.lang.String path, int targetWidth, int targetHeight)static ImagegetJpegScaled(java.lang.String path, int scaleNumerator, int scaleDenominator)java.lang.StringgetPath()Returns the path used to create the Image.voidgetPixelRow(byte[] fillIn, int y)Used in saveTo method.int[]getPixels()Used only at desktop to get the image's pixels.ImagegetRotatedScaledInstance(int scale, int angle, int fillColor)Creates a rotated and/or scaled version of this Image.ImagegetScaledInstance(int newWidth, int newHeight)Returns the scaled instance for this image.ImagegetSmoothScaledInstance(int newWidth, int newHeight)Returns the scaled instance using the area averaging algorithm for this image.ImagegetSmoothScaledInstance(int newWidth, int newHeight, int backColor)Deprecated.TotalCross 2 no longer uses the backColor parameter.ImagegetTouchedUpInstance(byte brightness, byte contrast)Creates a touched-up version of this Image with the specified brightness and contrast.intgetWidth()Returns the width of the image.intgetX()Returns 0intgetY()Returns 0inthashCode()ImagehwScaledBy(double scaleX, double scaleY)At non OpenGL devices, is the same of smoothScaledBy; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.ImagehwScaledFixedAspectRatio(int newSize, boolean isHeight)At non OpenGL devices, is the same of smoothScaledFixedAspectRatio; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.static booleanisSupported(java.lang.String filename)Returns true if the given filename is a supported image: Png or Jpeg.static ImageloadFrom(PDBFile cat, java.lang.String name)Loads an image from a PDB file, if it was previously saved using saveTo method.voidlockChanges()In OpenGL platforms, apply changes to the current texture and frees the memory used for the pixels in internal memory (the image can, however, be drawn on screen because the texture will be ready).voidnextFrame()Move to next frame in a multi-frame image.voidprevFrame()Move to the previous frame in a multi-frame image.static voidresizeJpeg(java.lang.String inputPath, java.lang.String outputPath, int maxPixelSize)voidsaveTo(PDBFile cat, java.lang.String name)Saves this image as a Windows .png file format to the given PDBFile.ImagescaledBy(double scaleX, double scaleY)Returns the scaled instance for this image, given the scale arguments.voidsetCurrentFrame(int nr)Move the contents of the given frame to the currently visible pixels.voidsetFrameCount(int n)Sets the frame count for this image.voidsetHwScaleFixedAspectRatio(int newSize, boolean isHeight)Sets the hwScaleW and hwScaleH fields based on the given new size.ImagesetTransparentColor(int color)Deprecated.use the alpha channel insteadImagesmoothScaledBy(double scaleX, double scaleY)Returns the scaled instance for this image, given the scale arguments.ImagesmoothScaledBy(double scaleX, double scaleY, int backColor)Deprecated.TotalCross 2 no longer uses the backColor parameter.ImagesmoothScaledFixedAspectRatio(int newSize, boolean isHeight)Returns the scaled instance using fixed aspect ratio for this image, given the scale arguments.ImagesmoothScaledFixedAspectRatio(int newSize, boolean isHeight, int backColor)Deprecated.TotalCross 2 no longer uses the backColor parameter.ImagesmoothScaledFromResolution(int originalRes)Returns a smooth scaled instance of this image with a fixed aspect ratio based on the given resolution (which is the resolution that you used to MAKE the image).ImagesmoothScaledFromResolution(int originalRes, int backColor)Deprecated.TotalCross 2 no longer uses the backColor parameter.static voidwriteFrameCount(java.lang.String filePath, int count)Utility method used to change the frame count of an image.
-
-
-
Field Detail
-
surfaceType
public int surfaceType
-
width
protected int width
-
height
protected int height
-
comment
public java.lang.String comment
A textual description stored in the PNG image.
-
transparentColor
public int transparentColor
Dumb field to keep compilation compatibility with TC 1
-
useAlpha
public boolean useAlpha
Dumb field to keep compilation compatibility with TC 1
-
alphaMask
public int alphaMask
A global alpha mask to be applied to the whole image when drawing it, ranging from 0 to 255.
-
hwScaleW
public double hwScaleW
Hardware accellerated scaling. The original image is scaled up or down by the video card when its displayed. In high end devices, the quality is the same of the algorithm used in smooth instances. Works only ifSettings.isOpenGLor on JavaSE. If you set this in non-opengl environments, nothing will happen; you should use the hwScaledBy, getHwScaledInstance and hwScaledFixedAspectRatio methods. To apply the changes, just callrepaint().- Since:
- TotalCross 2.0
- See Also:
setHwScaleFixedAspectRatio(int,boolean),hwScaledBy(double, double),hwScaledFixedAspectRatio(int, boolean),getHwScaledInstance(int, int)
-
hwScaleH
public double hwScaleH
Hardware accellerated scaling. The original image is scaled up or down by the video card when its displayed. In high end devices, the quality is the same of the algorithm used in smooth instances. Works only ifSettings.isOpenGLor on JavaSE. If you set this in non-opengl environments, nothing will happen; you should use the hwScaledBy, getHwScaledInstance and hwScaledFixedAspectRatio methods. To apply the changes, just callrepaint().- Since:
- TotalCross 2.0
- See Also:
setHwScaleFixedAspectRatio(int,boolean),hwScaledBy(double, double),hwScaledFixedAspectRatio(int, boolean),getHwScaledInstance(int, int)
-
NO_TRANSPARENT_COLOR
public static final int NO_TRANSPARENT_COLOR
Dumb field to keep compilation compatibility with TC 1- See Also:
- Constant Field Values
-
FADE_VALUE
public static int FADE_VALUE
Used in getFadedInstance().
-
-
Constructor Detail
-
Image
public Image(int width, int height) throws ImageExceptionCreates an image of the specified width and height. The image has a color depth (number of bitplanes) and color map that matches the default drawing surface. Here is an example of use:Image img = new Image(100,100); Graphics g = img.getGraphics(); g.backColor = Color.WHITE; g.fillRect(25,25,50,50); ... Graphics screenG = getGraphics(); screenG.drawImage(img,CENTER,CENTER);
- Throws:
ImageException
-
Image
public Image(java.lang.String path) throws ImageException, IOExceptionLoads and constructs an image from a file. The path given is the path to the image file. The file must be in 2, 16, 256, 24bpp color compressed (RLE) or uncompressed BMP bitmap format, or a PNG file, or a GIF file, or a JPEG file. If the image cannot be loaded, an ImageException will be thrown.- Throws:
ImageException- When the file was not found.IOException
-
Image
public Image(Stream s) throws ImageException, IOException
Loads a BMP, JPEG, GIF or PNG image from a totalcross.io.Stream. Note that Gif and BMP are supported only at desktop. Note that all the bytes of the given stream will be fetched, even those bytes that may follow this Image.- Throws:
IOExceptionImageException
-
Image
public Image(byte[] fullDescription) throws ImageExceptionParses an image from the given byte array. Note that the byte array must specify the full JPEG/PNG image, with headers (Gif/Bmp are supported at desktop only). Here is a code example:// create the image and fill it with something Image img = new Image(160,160); Graphics g = img.getGraphics(); for (int i =0; i < 16; i++) { g.backColor = Color.getRGB(10*i,10*i,10*i); g.fillRect(i*10,0,10,160); } img.applyChanges(); // save the bmp in a byte stream ByteArrayStream bas = new ByteArrayStream(4096); DataStream ds = new DataStream(bas); int totalBytesWritten = img.createPng(ds); // parse the saved png Image im = new Image(bas.getBuffer()); // Caution! the buffer may be greater than totalBytesWritten, but when parsing theres no problem. if (im.getWidth() > 0) // successfully parsed? { getGraphics().drawImage(im,CENTER,CENTER); Vm.sleep(2000); }Caution: if reading a JPEG file, the original array contents will be changed!- Throws:
ImageException- Thrown when something was wrong with the image.
-
Image
public Image(byte[] fullDescription, int length) throws ImageExceptionParses an image from the given byte array with the specified length. Note that the byte array must specify the full JPEG/PNG image, with headers (Gif/Bmp are supported at desktop only). Here is a code example:// create the image and fill it with something Image img = new Image(160,160); Graphics g = img.getGraphics(); for (int i =0; i < 16; i++) { g.backColor = Color.getRGB(10*i,10*i,10*i); g.fillRect(i*10,0,10,160); } img.applyChanges(); // save the bmp in a byte stream ByteArrayStream bas = new ByteArrayStream(4096); DataStream ds = new DataStream(bas); int totalBytesWritten = img.createPng(ds); // parse the saved png Image im = new Image(bas.getBuffer()); // Caution! the buffer may be greater than totalBytesWritten, but when parsing theres no problem. if (im.getWidth() > 0) // successfully parsed? { getGraphics().drawImage(im,CENTER,CENTER); Vm.sleep(2000); }Caution: if reading a JPEG file, the original array contents will be changed!- Throws:
ImageException- Thrown when something was wrong with the image.
-
-
Method Detail
-
setHwScaleFixedAspectRatio
public void setHwScaleFixedAspectRatio(int newSize, boolean isHeight)Sets the hwScaleW and hwScaleH fields based on the given new size. Does not work on Win32.
-
hwScaledFixedAspectRatio
public Image hwScaledFixedAspectRatio(int newSize, boolean isHeight) throws ImageException
At non OpenGL devices, is the same of smoothScaledFixedAspectRatio; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.- Throws:
ImageException- Since:
- TotalCross 2.0
-
getHwScaledInstance
public Image getHwScaledInstance(int width, int height) throws ImageException
At non OpenGL devices, is the same of getSmoothScaledInstance; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.- Throws:
ImageException- Since:
- TotalCross 2.0
-
hwScaledBy
public Image hwScaledBy(double scaleX, double scaleY) throws ImageException
At non OpenGL devices, is the same of smoothScaledBy; At openGL ones, this method shares all image informations while changing only the hwScaleW/hwScaleH parameters.- Throws:
ImageException- Since:
- TotalCross 2.0
-
getPixels
public int[] getPixels()
Used only at desktop to get the image's pixels.
-
getPath
public java.lang.String getPath()
Returns the path used to create the Image. For constructors that don't receive a path, returns null
-
setTransparentColor
@Deprecated public Image setTransparentColor(int color)
Deprecated.use the alpha channel insteadSets the transparent color of this image. A new image is NOT created.- Returns:
- The image itself
- Since:
- TotalCross 2.0
-
setFrameCount
public void setFrameCount(int n) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, ImageExceptionSets the frame count for this image. The width may be a multiple of the frame count. After the frame count is set, it cannot be changed.- Throws:
java.lang.IllegalArgumentExceptionjava.lang.IllegalStateExceptionImageException- Since:
- TotalCross 1.0
-
getFrameCount
public int getFrameCount()
Returns the frame count of this image.- Since:
- TotalCross 1.0
-
setCurrentFrame
public final void setCurrentFrame(int nr)
Move the contents of the given frame to the currently visible pixels.- Since:
- TotalCross 1.0
-
getCurrentFrame
public int getCurrentFrame()
Returns the current frame in a multi-frame image.- Since:
- TotalCross 1.0
-
nextFrame
public void nextFrame()
Move to next frame in a multi-frame image.- Since:
- TotalCross 1.0
-
prevFrame
public void prevFrame()
Move to the previous frame in a multi-frame image.- Since:
- TotalCross 1.0
-
getHeight
public int getHeight()
Returns the height of the image. You can check if the image is ok comparing this with zero.- Specified by:
getHeightin classGfxSurface
-
getWidth
public int getWidth()
Returns the width of the image. You can check if the image is ok comparing this with zero.- Specified by:
getWidthin classGfxSurface
-
getGraphics
public Graphics getGraphics()
Returns a new Graphics instance that can be used to drawing in this image.
-
applyChanges
public void applyChanges()
Applies any pending changes made in this image. In Open GL platforms, creates a texture for this image. This is already done, lazily, when the image is going to be painted. If you want to speedup paint, call this method as soon as any changes in the image are finished. In non-open gl platforms, does nothing.- Since:
- TotalCross 2
-
freeTexture
public void freeTexture()
In OpenGL platforms, attempts to free the texture associated with this object, if any. Does nothing if no texture is associated with this object, or if the texture associated is shared among multiple objects. This method provides a way of releasing memory resources without having to wait for garbage collection, but it can impact negatively on performance if used on objects that are still in use, causing the textures to be recreated. In non-OpenGL, does nothing. AVOID USING THIS METHOD IF UNSURE ABOUT IT.
-
lockChanges
public void lockChanges()
In OpenGL platforms, apply changes to the current texture and frees the memory used for the pixels in internal memory (the image can, however, be drawn on screen because the texture will be ready). Calling getGraphics after this method will return a null reference. In non-OpenGL, does nothing.- Since:
- TotalCross 2.0
-
changeColors
public final void changeColors(int from, int to)Changes all the pixels of the image from one color to the other. The current value of the transparent color is not changed. Using this routine, you can change the colors to any other you want. Note this replaces a single solid color by another solid color. If you want to change a gradient, or colorize an image, use the applyColor method instead. You must pass the color with the alpha channel (usually, 0xFF). For example, to change a red to green, use from=0xFFFF0000 (0xFF0000 with alpha=0xFF), to=0xFF00FF00.- See Also:
applyColor(int),applyColor2(int)
-
saveTo
public void saveTo(PDBFile cat, java.lang.String name) throws ImageException, IOException
Saves this image as a Windows .png file format to the given PDBFile.- The stored image size is limited to near 64Kb. Note that a stored image size has no relation to its size in pixels. For example, a 1300x1200 completely-white PNG file takes 7Kb of storage size but 6MB of RAM when loaded.
- The PDBFile can save multiple images, but the record must be prefixed with the image's name and must be sorted.
- This method finds the exact place where to insert the png and puts it there.
- If you want to create a png to be transfered by a stream to serial or socket then you must use the method createPng instead.
- If a record with this name already exists, it will be replaced.
- The name is always converted to lowercase and the method makes sure that .png is appended to it.
- To get the list of images in a PDBFile, just do a readString at the beginning of each record.
- To retrieve the image, use loadFrom method.
Here is a sample code:
// create the image and paint over it Image img = new Image(100,100); Graphics g = img.getGraphics(); g.backColor = Color.getRGB(100,150,200); g.fillRect(25,25,50,50); g.foreColor = Color.WHITE; g.drawCircle(50,50,20); // create the PDBFile to save the image. You must change CRTR to match your apps creator ID String pdbName = "images.CRTR.TYPE"; PDBFile pdb = new PDBFile(pdbName, PDBFile.CREATE); img.saveTo(pdb, "boxcircle.png"); pdb.close(); // load the previously created image PDBFile pdb = new PDBFile(pdbName, PDBFile.READ_WRITE); add(new ImageControl(Image.loadFrom(pdb,"boxcircle.png")),CENTER,CENTER); pdb.close();
Here's a code that lists the images in a PDB (saved using this method).public static String[] list(PDBFile cat) throws IOException { DataStream ds = new DataStream(cat); int n = cat.getRecordCount(); String[] names = new String[n]; for (int i =0; i < n; i++) { cat.setRecordPos(i); names[i] = ds.readString(); } return names; }- Throws:
ImageExceptionIOException- See Also:
createPng(totalcross.io.Stream),loadFrom(PDBFile, String)
-
loadFrom
public static Image loadFrom(PDBFile cat, java.lang.String name) throws IOException, ImageException
Loads an image from a PDB file, if it was previously saved using saveTo method.- Throws:
IOExceptionImageException- Since:
- TotalCross 1.22
- See Also:
saveTo(PDBFile, String)
-
createJpg
public void createJpg(Stream s, int quality) throws ImageException, IOException
Saves this image as a jpeg file to the given stream.
NOT supported on Blackberry.- Parameters:
s- The output stream used to write the jpeg.quality- The quality of the image; 100 = no compression, 90 = medium compression, 80 = high compression. Anything below 80 may greatly redude the image's quality. 85 is a common value. In JavaSE, the quality argument is ignored.- Throws:
ImageExceptionIOException
-
createJpg4B
public void createJpg4B(Stream s, int quality) throws ImageException, IOException
- Throws:
ImageExceptionIOException
-
createPng
public void createPng(Stream s) throws ImageException, IOException
Saves this image as a 24 BPP .png file format (if useAlpha is true, it saves as 32 BPP), to the given stream. If you're sending the png through a stream but not saving to a PDBFile, you can use this method. If you're going to save it to a PDBFile, then you must use the saveTo method.- Throws:
ImageExceptionIOException- See Also:
saveTo(totalcross.io.PDBFile, java.lang.String)
-
getPixelRow
public final void getPixelRow(byte[] fillIn, int y)Used in saveTo method. Fills in the y row into the fillIn array. there must be enough space for the full line be filled, with width*4 bytes. The alpha channel is NOT stripped off.
-
getScaledInstance
public Image getScaledInstance(int newWidth, int newHeight) throws ImageException
Returns the scaled instance for this image. The algorithm used is the replicate scale: not good quality, but fast.- Throws:
ImageException- Since:
- SuperWaba 3.5
-
getSmoothScaledInstance
public Image getSmoothScaledInstance(int newWidth, int newHeight) throws ImageException
Returns the scaled instance using the area averaging algorithm for this image. Example:Image img2 = img.getSmoothScaledInstance(200,200);
In device and JavaSE it uses a Catmull-rom resampling, and in Blackberry it uses an area-average resampling. The reason is that the Catmull-rom consumes more memory and is also slower than the area-average, although the final result is much better.- Throws:
ImageException- Since:
- TotalCross 1.0
-
scaledBy
public Image scaledBy(double scaleX, double scaleY) throws ImageException
Returns the scaled instance for this image, given the scale arguments. The algorithm used is the replicate scale, not good quality, but fast. Given values must be > 0.- Throws:
ImageException- Since:
- SuperWaba 4.1
-
smoothScaledBy
public Image smoothScaledBy(double scaleX, double scaleY) throws ImageException
Returns the scaled instance for this image, given the scale arguments. Given values must be > 0. The backColor replaces the transparent pixel of the current image to produce a smooth border. Example:Image img2 = img.smoothScaledBy(0.75,0.75, getBackColor());
- Throws:
ImageException- Since:
- TotalCross 1.0
-
smoothScaledFixedAspectRatio
public Image smoothScaledFixedAspectRatio(int newSize, boolean isHeight) throws ImageException
Returns the scaled instance using fixed aspect ratio for this image, given the scale arguments. Given values must be > 0. This method is useful to resize an image, specifying only one of its sides: the width or the height. The other side is computed to keep the aspect ratio.- Parameters:
newSize- The new size (width or height) for the imageisHeight- If true, the newSize is considered as the new height of the image. If false, the newSize is considered the new width of the image. Example:Image img2 = img.smoothScaledFixed(fmH, true, -1);
- Throws:
ImageException- Since:
- TotalCross 1.53
-
getRotatedScaledInstance
public Image getRotatedScaledInstance(int scale, int angle, int fillColor) throws ImageException
Creates a rotated and/or scaled version of this Image. A newImageobject is returned which will render the image at the specifiedscaleratio and rotationangle. After rotation, the empty parts of the rectangular area of the resulting image are filled with thefillcolor. Ifcoloris-1, then the fill color is the transparent color, or white if none.Notes
- the new image will probably have a different size of this image.
- if you want just to scale, use the getScaledInstance or scaleBy (and the smooth ones) instead, because they are faster.
- If you need a smooth rotate and scale, scale it first with getScaledInstance then rotate without scale (or vice-versa)
- In multiframe images, each image is rotated/scaled independently.
- Parameters:
scale- a number greater than or equal to 0 stating the percentage of scaling to be performed. 100 is not scaling, 200 doubles the size, 50 shrinks the image by 2angle- the rotation angle, expressed in trigonometric degreesfillColor- the fill color; -1 indicates the transparent color of this image or Color.WHITE if the transparentColor was not set; use 0 for a transparent background, or 0xFF000000 for the BLACK color.- Throws:
ImageException
-
getFadedInstance
@Deprecated public Image getFadedInstance(int backColor) throws ImageException
Deprecated.Use getFadedInstance() insteadCreates a faded instance of this image, interpolating all pixels with the given background color.- Throws:
ImageException- Since:
- TotalCross 1.01
- See Also:
getFadedInstance()
-
getFadedInstance
public Image getFadedInstance() throws ImageException
Creates a faded instance of this image, decreasing the alpha-channel by 128 for all pixels.- Throws:
ImageException- Since:
- TotalCross 2.0
- See Also:
FADE_VALUE
-
getAlphaInstance
public Image getAlphaInstance(int delta) throws ImageException
Adds the given value to each pixel's alpha-channel of this image. Only the pixels that don't have a 0 alpha are changed.- Throws:
ImageException- Since:
- TotalCross 2.0
-
getTouchedUpInstance
public Image getTouchedUpInstance(byte brightness, byte contrast) throws ImageException
Creates a touched-up version of this Image with the specified brightness and contrast. A newImageobject is returned which will render the image at the specifiedbrigthnessand the specifiedcontrast.- Parameters:
brightness- a number between -128 and 127 stating the desired level of brightness. 127 is the highest brightness level (white image), -128 is no brightness (darkest image).contrast- a number between -128 and 127 stating the desired level of contrast. 127 is the highest contrast level, -128 is no contrast.- Throws:
ImageException
-
getX
public int getX()
Returns 0- Specified by:
getXin classGfxSurface
-
getY
public int getY()
Returns 0- Specified by:
getYin classGfxSurface
-
isSupported
public static boolean isSupported(java.lang.String filename)
Returns true if the given filename is a supported image: Png or Jpeg. Gif and Bmp are supported on JavaSE only.- Since:
- TotalCross 1.0
-
getFrameInstance
public final Image getFrameInstance(int frame) throws ImageException
In a multi-frame image, returns a copy of the given frame. In a single-frame image, gets a copy of the image.- Throws:
ImageException- Since:
- TotalCross 1.12
-
applyColor
public final void applyColor(int color)
Applies the given color r,g,b values to all pixels of this image, preserving the transparent color and alpha channel, if set.- Parameters:
color- The color to be applied- Since:
- TotalCross 1.12
-
smoothScaledFromResolution
public final Image smoothScaledFromResolution(int originalRes) throws ImageException
Returns a smooth scaled instance of this image with a fixed aspect ratio based on the given resolution (which is the resolution that you used to MAKE the image). The target size is computed asimage_size*min(screen_size)/original_resolution- Parameters:
originalRes- The original resolution that the image was developed for. Its a good idea to create images for 320x320 and then scale them down.- Throws:
ImageException- Since:
- TotalCross 1.12
-
equals
public boolean equals(java.lang.Object o)
Returns true if the given Image object has the same size and RGB pixels of this one. The alpha-channel is ignored.- Overrides:
equalsin classjava.lang.Object- Since:
- TotalCross 1.3
-
applyColor2
public final void applyColor2(int color)
Applies the given color r,g,b values to all pixels of this image, preserving the transparent color and alpha channel, if set. This method is used to colorize the Android buttons. If the color's alpha is 0xAA, the image's alpha will also be changed. This is used by the Spinner.- Parameters:
color- The color to be applied- Since:
- TotalCross 1.3
-
getSmoothScaledInstance
@Deprecated public Image getSmoothScaledInstance(int newWidth, int newHeight, int backColor) throws ImageException
Deprecated.TotalCross 2 no longer uses the backColor parameter.- Throws:
ImageException
-
smoothScaledBy
@Deprecated public Image smoothScaledBy(double scaleX, double scaleY, int backColor) throws ImageException
Deprecated.TotalCross 2 no longer uses the backColor parameter.- Throws:
ImageException
-
smoothScaledFixedAspectRatio
@Deprecated public Image smoothScaledFixedAspectRatio(int newSize, boolean isHeight, int backColor) throws ImageException
Deprecated.TotalCross 2 no longer uses the backColor parameter.- Throws:
ImageException
-
smoothScaledFromResolution
@Deprecated public final Image smoothScaledFromResolution(int originalRes, int backColor) throws ImageException
Deprecated.TotalCross 2 no longer uses the backColor parameter.- Throws:
ImageException
-
applyFade
public void applyFade(int fadeValue)
Applies the given fade value to r,g,b of this image while preserving the alpha value.
-
writeFrameCount
public static void writeFrameCount(java.lang.String filePath, int count)Utility method used to change the frame count of an image. This method exists in java only, not on device. The frame count of a TotalCross' Image is stored in a comment inside the PNG file. If you create a PNG with many frames and don't want to keep calling the setFrameCount manually, you can call this method like:Image.writeFrameCount("c:/project/src/images/people.png",2);Be careful that this must be done once only; this method does not exist in the device and will abort the vm if you try to call it there!- Since:
- TotalCross 3.1
-
getCopy
public Image getCopy() throws ImageException
Gets a copy of this image; if the image is multi-framed, returns a copy of the first frame.- Throws:
ImageException- Since:
- TotalCross 3.1
-
getClippedInstance
public Image getClippedInstance(int x, int y, int w, int h) throws ImageException
Returns a clipped image from the current position. Note that you must ensure that the values are correct or an exception will be thrown- Throws:
ImageException
-
resizeJpeg
public static void resizeJpeg(java.lang.String inputPath, java.lang.String outputPath, int maxPixelSize)
-
getJpegBestFit
public static Image getJpegBestFit(java.lang.String path, int targetWidth, int targetHeight) throws java.io.IOException, ImageException
- Throws:
java.io.IOExceptionImageException
-
getJpegScaled
public static Image getJpegScaled(java.lang.String path, int scaleNumerator, int scaleDenominator) throws java.io.IOException, ImageException
- Throws:
java.io.IOExceptionImageException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-