import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author Gyandeepak Dubey
*/
public class Main {
static byte[] b;
public byte[] obtainByteData() throws IOException {
InputStream inputStream = getClass().getResourceAsStream("ant.jpg");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
byte[] bytes = new byte[512];
// Read bytes from the input stream in bytes.length-sized chunks and write
// them into the output stream
int readBytes;
while ((readBytes = inputStream.read(bytes)) > 0) {
outputStream.write(bytes, 0, readBytes);
}
// Convert the contents of the output stream into a byte array
byte[] byteData = outputStream.toByteArray();
// Close the streams
inputStream.close();
outputStream.close();
return byteData;
}
Image GetFromJPEG(byte[] jpegBytes)
{
Image jpegImage = null;
//System.out.println("Jpeg data length: " + jpegBytes.length);
try
{
jpegImage = Toolkit.getDefaultToolkit().createImage(jpegBytes);
}
catch (Exception e)
{
System.out.println("Problem creating image: " + e.toString() + ": " + e.getMessage());
}
return jpegImage;
}
}