Professional Documents
Culture Documents
ImageUtil Java
ImageUtil Java
imagebit;
import java.awt.image.BufferedImage;
import java.io.*;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.imageio.ImageIO;
import msc.mythesis.enhancedlsbmethod.EnhancedLSBMethodException;
/**
* Image utilities
*/
/**
* Method to generate a random image filled with noise. The size of the image will be calculated
based on the
* param dataLength Length of data in bytes which the image should be able to accommodate
* throws EnhancedLSBMethodException
*/
int width = 0;
int height = 0;
try
random = SecureRandom.getInstance("SHA1PRNG");
random.nextBytes(rgbValue);
image.setRGB(x, y, ImageBitDataHeader.byteToInt(rgbValue[0])
+ (ImageBitDataHeader.byteToInt(rgbValue[1]) << 8)
}
return image;
catch(NoSuchAlgorithmException nsaEx)
/**
* throws EnhancedLSBMethodException
*/
throws EnhancedLSBMethodException
try
if(imageFileName != null)
{
imageType = imageFileName.substring(imageFileName.lastIndexOf('.') + 1).toLowerCase();
if(!plugin.getWritableFileExtensions().contains(imageType))
if(imageType.equals("jp2"))
else
return barrOS.toByteArray();
catch(IOException ioEx)
/**
* throws EnhancedLSBMethodException
*/
throws EnhancedLSBMethodException
try
if(imageData == null)
return null;
if(image == null)
return image;
catch(IOException ioEx)