My video bailey.mpg from which i created .png images using xuggler method, then i read each image in byte array and append hash as delimiter and text data in this byte array and recreate image using this byte array.
Now i am reconstructing video in .avi format from this (text appended images)set of images. By getting the sets of .png images from new avi video using xuggler .I am reading each image in byte array, and i am searching delimiter in byte array of image's set, but I am unable to find hash delimiter.I think this means text data loss during creation of video.
what should i do?
Code for create images from video
package DifferentPackage;
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
import com.xuggle.xuggler.Global;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author pratibha
*/
public class VideoIntoFrames {
public static final double SECONDS_BETWEEN_FRAMES =1;
String inputFilename;
private static final String outputFilePrefix = "C:\\photo\\image_";
// The video stream index, used to ensure we display frames from one and
//only one video stream from the media container.
private static int mVideoStreamIndex = -1;
// Time of last frame write
private static long mLastPtsWrite = Global.NO_PTS;
public static final long MICRO_SECONDS_BETWEEN_FRAMES =(long)(100 * SECONDS_BETWEEN_FRAMES);
int FrameNo=0;
public VideoIntoFrames(String filepath){
inputFilename=filepath;
IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
// stipulate that we want BufferedImages created in BGR 24bit color space
mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
mediaReader.addListener(new ImageSnapListener());
// read out the contents of the media file and
// dispatch events to the attached listener
while (mediaReader.readPacket() == null) ;
}
private class ImageSnapListener extends MediaListenerAdapter {
public void onVideoPicture(IVideoPictureEvent event) {
if (event.getStreamIndex() != mVideoStreamIndex) {
// if the selected video stream id is not yet set, go ahead an
// select this lucky video stream
if (mVideoStreamIndex == -1)
mVideoStreamIndex = event.getStreamIndex();
// no need to show frames from this video stream
else
return;
}
// if uninitialized, back date mLastPtsWrite to get the very first frame
if (mLastPtsWrite == Global.NO_PTS)
mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;
// if it's time to write the next frame
if (event.getTimeStamp() - mLastPtsWrite >=
MICRO_SECONDS_BETWEEN_FRAMES) {
++FrameNo;
String outputFilename = dumpImageToFile(event.getImage());
// indicate file written
double seconds = ((double) event.getTimeStamp()) /
Global.DEFAULT_PTS_PER_SECOND;
System.out.printf(
"at elapsed time of %6.3f seconds wrote: %s\n",
seconds, outputFilename);
// update last write time
mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;
}
}
private String dumpImageToFile(BufferedImage image) {
try {
String outputFilename = outputFilePrefix +FrameNo+ ".gif";
ImageIO.write(image, "jpg", new File(outputFilename));
return outputFilename;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public static void main(String args[]){
String path="D:/bailey.mpg";
VideoIntoFrames v=new VideoIntoFrames(path);
}
}
All images are save at c:/photo .Code for Insert Text Data in image_1.gif is
try{
String data="My Name is ";
int[] charValue=new int[data.length()];
for(int rowIndex=0;rowIndex<charValue.length;rowIndex++){
charValue[rowIndex]=data.charAt(rowIndex);
}
File videoFile = new File("C:/photo/image_1.gif");
FileInputStream videoInput = new FileInputStream(videoFile);
int VideoByte = -1;
List<Byte> bytes = new ArrayList<Byte>();
while ((VideoByte = videoInput.read()) != -1) {
bytes.add((byte) VideoByte);
}
byte[] ByteOfVideo = new byte[bytes.size()];
for (int count = 0; count < ByteOfVideo.length; count++) {
ByteOfVideo[count] = bytes.get(count);
// System.out.println(count+" of ByteOfImage "+ByteOfVideo[count]);
}
////////////////////////////////////#////////////////////////
/////now insert actual image fRames,Row and Columns
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
for (int i = 0; i < ByteOfVideo.length; i++) {
byteOut.write(ByteOfVideo[i]);
}
byte[] HashArray = "#".getBytes();
byteOut.write(HashArray);
byteOut.write(HashArray);
byteOut.write(HashArray);
byteOut.write(HashArray);
byteOut.write(HashArray);
/// String retrievedString = new String(FrameByteArray, "UTF-8");
for (int i = 0; i < charValue.length; i++) {
System.out.println(" NameArray in Bytes" + charValue[i]);
byteOut.write(charValue[i]);
}
////insert #
//////write this Video File
String FinalModifiedVideo="C:\\photo\\image_1.gif";
File ModifiedFile=new File(FinalModifiedVideo);
DataOutputStream out=new DataOutputStream(new FileOutputStream(ModifiedFile));
byteOut.writeTo(out);
out.close();
System.out.println("Process End");
}
catch(Exception e){
e.printStackTrace();
}
Code for create video from image set(images in c:/photo) folder.this create image.avi video
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Frame;
import test.*;
import ch.randelshofer.media.avi.AVIOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* #author Inbo
*/
public class MyVideoWriter {
static ArrayList<String> img = new ArrayList();
public static void readFiles() {
String path = "C:\\photo\\";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
int c = 0;
for (int i = 0; i <799; i++) {
img.add(path + "\\image_" + (i + 1) + ".gif");
}
// System.out.println(img);
}
public MyVideoWriter(String path) {
readFiles();
try {
AVIOutputStream AVIout = new AVIOutputStream(new File(path + ".avi"), AVIOutputStream.VideoFormat.JPG);
AVIout.setVideoCompressionQuality(1);
//AVIout.setFrameRate(10);
AVIout.setVideoDimension(352, 240);
for (int i = 0; i < img.size(); i++) {
AVIout.writeFrame(new File(img.get(i)));
}
AVIout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
String path="C:\\image";
MyVideoWriter mv = new MyVideoWriter(path);
}
}
Related
I am trying to take an initial CSV file, pass it through a class that checks another file if it has an A or a D to then adds or deletes the associative entry to an array object.
example of pokemon.csv:
1, Bulbasaur
2, Ivysaur
3, venasaur
example of changeList.csv:
A, Charizard
A, Suirtle
D, 2
That being said, I am having a lot of trouble getting the content of my new array to a new CSV file. I have checked to see whether or not my array and class files are working properly. I have been trying and failing to take the final contents of "pokedex1" object array into the new CSV file.
Main File
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class PokedexManager {
public static void printArray(String[] array) {
System.out.print("Contents of array: ");
for(int i = 0; i < array.length; i++) {
if(i == array.length - 1) {
System.out.print(array[i]);
}else {
System.out.print(array[i] + ",");
}
}
System.out.println();
}
public static void main(String[] args) {
try {
//output for pokedex1 using PokemonNoGaps class
PokemonNoGaps pokedex1 = new PokemonNoGaps();
//initializes scanner to read from csv file
String pokedexFilename = "pokedex.csv";
File pokedexFile = new File(pokedexFilename);
Scanner pokescanner = new Scanner(pokedexFile);
//reads csv file, parses it into an array, and then adds new pokemon objects to Pokemon class
while(pokescanner.hasNextLine()) {
String pokeLine = pokescanner.nextLine();
String[] pokemonStringArray = pokeLine.split(", ");
int id = Integer.parseInt(pokemonStringArray[0]);
String name = pokemonStringArray[1];
Pokemon apokemon = new Pokemon(id, name);
pokedex1.add(apokemon);
}
//opens changeList.csv file to add or delete entries from Pokemon class
String changeListfilename = "changeList.csv";
File changeListFile = new File(changeListfilename);
Scanner changeScanner = new Scanner(changeListFile);
//loads text from csv file to be parsed to PokemonNoGaps class
while(changeScanner.hasNextLine()) {
String changeLine = changeScanner.nextLine();
String[] changeStringArray = changeLine.split(", ");
String action = changeStringArray[0];
String nameOrId = changeStringArray[1];
//if changList.csv file line has an "A" in the first spot add this entry to somePokemon
if(action.equals("A")) {
int newId = pokedex1.getNewId();
String name = nameOrId;
Pokemon somePokemon = new Pokemon(newId, name);
pokedex1.add(somePokemon);
}
//if it has a "D" then send it to PokemonNoGaps class to delete the entry from the array
else { //"D"
int someId = Integer.parseInt(nameOrId);
pokedex1.deleteById(someId);
}
//tests the action being taken and the update to the array
//System.out.println(action + "\t" + nameOrId + "\n");
System.out.println(pokedex1);
//*(supposedly)* prints the resulting contents of the array to a new csv file
String[] pokemonList = changeStringArray;
try {
String outputFile1 = "pokedex1.csv";
FileWriter writer1 = new FileWriter(outputFile1);
writer1.write(String.valueOf(pokemonList));
} catch (IOException e) {
System.out.println("\nError writing to Pokedex1.csv!");
e.printStackTrace();
}
}
//tests final contents of array after being passed through PokemonNoGaps class
//System.out.println(pokedex1);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
PokemonNoGaps class file:
public class PokemonNoGaps implements ChangePokedex {
private Pokemon[] pokedex = new Pokemon[1];
private int numElements = 0;
private static int id = 0;
// add, delete, search
#Override
public void add(Pokemon apokemon) {
// if you have space
this.pokedex[this.numElements] = apokemon;
this.numElements++;
// if you don't have space
if(this.numElements == pokedex.length) {
Pokemon[] newPokedex = new Pokemon[ this.numElements * 2]; // create new array
for(int i = 0; i < pokedex.length; i++) { // transfer all elements from array into bigger array
newPokedex[i] = pokedex[i];
}
this.pokedex = newPokedex;
}
this.id++;
}
public int getNewId() {
return this.id + 1;
}
#Override
public void deleteById(int id) {
for(int i = 0; i < numElements; i++) {
if(pokedex[i].getId() == id) {
for(int j = i+1; j < pokedex.length; j++) {
pokedex[j-1] = pokedex[j];
}
numElements--;
pokedex[numElements] = null;
}
}
}
public Pokemon getFirstElement() {
return pokedex[0];
}
public int getNumElements() {
return numElements;
}
public String toString() {
String result = "";
for(int i = 0; i < this.numElements; i++) {
result += this.pokedex[i].toString() + "\n";
}
return result;
}
}
Excpeted output:
1, Bulbasaur
3, Venasaur
4, Charizard
5, Squirtle
Am i using the wrong file writer? Am I calling the file writer at the wrong time or incorrectly? In other words, I do not know why my output file is empty and not being loaded with the contents of my array. Can anybody help me out?
I spotted a few issues whilst running this. As mentioned in previous answer you want to set file append to true in the section of code that writes to the new pokedx1.csv
try {
String outputFile1 = "pokedex1.csv";
FileWriter fileWriter = new FileWriter(prefix+outputFile1, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
for(String pokemon : pokedex1.toString().split("\n")) {
System.out.println(pokemon);
bw.write(pokemon);
}
bw.flush();
bw.close();
} catch (IOException e) {
System.out.println("\nError writing to Pokedex1.csv!");
e.printStackTrace();
}
I opted to use buffered reader for the solution. Another issue I found is that your reading pokedex.csv but the file is named pokemon.csv.
String pokedexFilename = "pokemon.csv";
I made the above change to fix this issue.
On a side note I noticed that you create several scanners to read the two files. With these types of resources its good practice to call the close method once you have finished using them; as shown below.
Scanner pokescanner = new Scanner(pokedexFile);
// Use scanner code here
// Once finished with scanner
pokescanner.close();
String outputFile1 = "pokedex1.csv";
FileWriter writer1 = new FileWriter(outputFile1);
appears to be within your while loop so a new file will be created every time.
Either use the FileWriter(File file, boolean append) constructor or create before the loop
I have a project where I am to write data (strings and ints) into a binary random access file, and read the data in a separate class. The problem I have is I'm trying to iterate through the file and read the data in a specific order (int, String, String, int), however the Strings are various byte sizes.
I am getting an EOFException but cannot figure out why.
Here is the class which writes the data. Part of the requirements is to limit the number of bytes for the Strings and catch a user defined exception if they are exceeded.
import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.File;
public class QuestionBank {
private RandomAccessFile file;
private ArrayList <Questions> listQuestions;
public QuestionBank(){
file = null;
listQuestions = new ArrayList<Questions>();
}
public void storeQuestion (Questions ques) throws IOException {
ques = new Questions(ques.getQuesIDNum(), ques.getQuestion(), ques.getAnswer(), ques.getValue());
listQuestions.add(ques);
byte[] quesBytes = ques.getQuestion().getBytes("UTF-8");
byte[] ansBytes = ques.getAnswer().getBytes("UTF-8");
try {
file = new RandomAccessFile(new File("Question.bin"), "rw");
long fileSize = file.length();
file.seek(fileSize);
file.writeInt(ques.getQuesIDNum());
file.writeUTF(ques.getQuestion());
for (int i = 0; i <= 50 - ques.getQuestion().length(); i++){
file.writeByte(50);
}
if (quesBytes.length > 50) {
throw new ByteSizeException("Question has too many bytes");
}
file.writeUTF(ques.getAnswer());
for (int i = 0; i <= 20 - ques.getAnswer().length(); i++){
file.writeByte(20);
}
if (ansBytes.length > 20) {
throw new ByteSizeException("Answer has too many bytes");
}
file.writeInt(ques.getValue());
file.close();
} catch (IOException e) {
System.out.println("I/O Exception Found");
} catch (ByteSizeException eb) {
System.out.println("String has too many bytes");
}
}
Here is the class which reads the file.
import java.util.ArrayList;
import java.util.Random;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.File;
public class TriviaGame {
public static final int RECORD = 78;
private ArrayList<Questions> quesList;
private int IDNum;
private String question;
private String answer;
private int points;
public TriviaGame() {
quesList = new ArrayList<Questions>();
IDNum = 0;
question = "";
answer = "";
points = 0;
}
public void read(){
try {
RandomAccessFile file;
file = new RandomAccessFile(new File("Question.bin"), "r");
long fileSize = file.length();
long numRecords = fileSize/RECORD;
file.seek(0);
for (int i = 0; i < numRecords; i++){
IDNum = file.readInt();
question = file.readUTF();
answer = file.readUTF();
points = file.readInt();
System.out.println("ID: " + IDNum + " Question: " + question + " Answer: " + answer + " Points: " + points);
}
file.close();
} catch (IOException e) {
System.out.println(e.getClass());
System.out.println("I/O Exception found");
}
}
}
Thanks
file.writeUTF(ques.getQuestion());
Here you have written the question.
for (int i = 0; i <= 50 - ques.getQuestion().length(); i++){
file.writeByte(50);
}
if (quesBytes.length > 50) {
throw new ByteSizeException("Question has too many bytes");
}
Here for some unknown reason you are padding the question to 50 bytes. Remove. Same with the answer. You are using readUTF() to read both of these, so all you need is writeUTF() to write them. No padding required.
Or, if you insist on this padding, you have to skip over it when reading: after the first readUTF(), you need to skip over the padding.
So I am trying to use JFile chooser to read strings in from a .txt file and save them into an array. I though I had this a set up right but the problem is nothing is getting put into the array because when I display the array it is all nulls. I am new to java so I am not that familiar with using JFile chooser. The window pops up and everything and lets me choose a file so I think it is working somewhat. Also if you could explain to me what all of the code mean regarding the JFile chooser I would be very grateful, most of what I have is from videos, online and books and I kind of understand it but I definitely need some further explanation.
import java.io.*;
import java.util.Scanner; // All My imports
import javax.swing.*;
public class SpellChecker // I am creating a spell checker
{
static String check[] = new String[50]; // My array to save all of the strings in a file
static int index = 0; // index will incremented whenever a string is added to the array
public static void main(String args[])
{
getFile(); // Method call that opens file and saves all the data to the array
for(int i = 0; i < check.length - 1; i++) // outputting the array
{
System.out.println(check[i]);
}
}
public static void getFile()
{
JFileChooser chooser;
File infile, directory;
int status;
String wordToCheck;
chooser = new JFileChooser( );
status = chooser.showOpenDialog(null);
if(status == JFileChooser.APPROVE_OPTION)
{
infile = chooser.getSelectedFile();
directory = chooser.getCurrentDirectory();
try
{
infile = new File(chooser.getSelectedFile().getAbsolutePath());
Scanner scanner = new Scanner(infile);
while(scanner.hasNext())
{
wordToCheck = scanner.next();
if(index == check.length)
{
String tempAr[] = new String[check.length*2];
for(int i = 0; i < index; i++)
{
tempAr[i] = check[i];
}
check = tempAr;
}
check[index] = wordToCheck;
index++;
}
scanner.close();
}
catch(IOException e)
{
System.out.println("Error");
}
}
else
{
System.out.println("Open File dialog canceled");
}
}
I want to split my audio file (.wav format) in frames of 32 milliseconds each. Sampling frequency - 16khz, number of channels - 1(mono), pcm signal, sample size = 93638.
After getting the data in the byte format, I am converting the byte array storing the wav file data to double array since I require it to pass it to a method which accepts a double array, I am using the following code can someone tell me how to proceed?
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.ByteBuffer;
public class AudioFiles
{
public static void main(String[] args)
{
String file = "D:/p.wav";
AudioFiles afiles = new AudioFiles();
byte[] data1 = afiles.readAudioFileData(file);
byte[] data2 = afiles.readWAVAudioFileData(file);
System.out.format("data len1: %d\n", data1.length);
System.out.format("data len2: %d\n", data2.length);
/* for(int i=0;i<data2.length;i++)
{
System.out.format("\t"+data2[i]);
}*/
System.out.println();
/* for(int j=0;j<data1.length;j++)
{
System.out.format("\t"+data1[j]);
}*/
System.out.format("diff len: %d\n", data2.length - data1.length);
double[] d = new double[data1.length];
d = toDoubleArray(data1);
for (int j = 0; j < data1.length; j++)
{
System.out.format("\t" + d[j]);
}
daub a = new daub();
a.daubTrans(d);
}
public static double[] toDoubleArray(byte[] byteArray)
{
int times = Double.SIZE / Byte.SIZE;
double[] doubles = new double[byteArray.length / times];
for (int i = 0; i < doubles.length; i++)
{
doubles[i] = ByteBuffer.wrap(byteArray, i * times, times).getDouble();
}
return doubles;
}
public byte[] readAudioFileData(final String filePath)
{
byte[] data = null;
try
{
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final File file = new File(filePath);
final AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(file);
byte[] buffer = new byte[4096];
int c;
while ((c = audioInputStream.read(buffer, 0, buffer.length)) != -1)
{
baout.write(buffer, 0, c);
}
audioInputStream.close();
baout.close();
data = baout.toByteArray();
}
catch (Exception e)
{
e.printStackTrace();
}
return data;
}
public byte[] readWAVAudioFileData(final String filePath)
{
byte[] data = null;
try
{
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(filePath));
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, baout);
audioInputStream.close();
baout.close();
data = baout.toByteArray();
}
catch (Exception e)
{
e.printStackTrace();
}
return data;
}
}
I want to pass the double array d to method performing wavelet transform, in the frames of 32 millisecond since it accepts a double array.
In my previous question I was given a reply that:
At 16kHz sample rate you'll have 16 samples per millisecond. Therefore, each 32ms frame would be 32*16=512 mono samples. Multiply by the number of bytes-per-sample (typically 2 or 4) and that will be the number of bytes per frame.
I want to know whether my frame size changes when I convert my array from byte format to double format or does it remains the same??
My Previous Question.
i have written a program to encrypt an image in Netbeans. The program works fine when running from netbeans but when i build it into a .jar file its not working, it cannot read the image even though i placed the image file in the same folder as the .jar file.
package test;
import java.io.IOException;
import java.io.File;
/**
*
* #author AMaR
*/
public class Test {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException, Exception {
File EnImage = new File("encrypted.png");
File DeImage = new File("decrypted.png");
int[] pixels;
LoadImage l = new LoadImage();
l.load();
pixels= l.getImagePixels();
RC4New rc4 = new RC4New();
int key[]= {13,2,4,6,};
// int data[]={5,10,90,5};
rc4.KSA(key);
int[] text = rc4.PRNG(pixels);
l.write((int)512,(int)512,text,EnImage);
//RC4New rc41 = new RC4New();
rc4.KSA(key);
int[] text1 = rc4.PRNG(text);
l.write((int)512,(int)512,text1,DeImage);
/* for(int i=0;i<text.length;i++){
System.out.println(text[i]);
}
RC4New rc41 = new RC4New();
rc4.KSA(key);
int[] text1 = rc4.PRNG(text);
for(int i=0;i<text1.length;i++){
System.out.println(text1[i]);
}
*/
System.out.println("length:"+pixels.length);
// l.write((int)512,(int)512,text);
// TODO code application logic here
}
}
//encryption
package test;
/**
*
* #author AMaR
*/
public class RC4New {
int state[] = new int[256];
int j;
/**
*
* #param key
*/
public void KSA(int[] key){
int tmp;
for (int i=0; i < 256; i++) {
state[i] = i;
}
j=0;
for (int i=0; i < 256; i++) {
j = (j + state[i] + key[i % key.length]) % 256;
tmp = state[i];
state[i] = state[j];
state[j] = tmp;
}
}
public int[] PRNG(int[] data){
int tmp,k;
int i=0;
j=0;
int[] cipherText = new int[data.length];
for(int x=0;x<data.length;x++){
i = (i + 1) % 256;
j = (j + state[i]) % 256;
tmp = state[i];
state[i] = state[j];
state[j] = tmp;
k = state[(state[i] + state[j]) % 256];
cipherText[x]= (data[x] ^ k);
}
return cipherText;
}
}
//loading/writing image
package test;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.WritableRaster;
/**
*
* #author AMaR
*/
public class LoadImage {
BufferedImage image;
void load()throws Exception {
// FIle newfile = new File("lena.png)
image = ImageIO.read(getClass().getResourceAsStream("lena.png"));
}
public Dimension getImageSize() {
return new Dimension(image.getWidth(), image.getHeight());
}
public int[] getImagePixels() {
int [] dummy = null;
int wid, hgt;
// compute size of the array
wid = image.getWidth();
hgt = image.getHeight();
// start getting the pixels
Raster pixelData;
pixelData = image.getData();
return pixelData.getPixels(0, 0, wid, hgt, dummy);
}
#SuppressWarnings("empty-statement")
public void write(int width ,int height, int[] pixels,File outputfile) {
try {
// retrieve image
BufferedImage writeImage = new BufferedImage(512, 512, BufferedImage.TYPE_BYTE_GRAY);;
// File outputfile = new File("encrypted.png");
WritableRaster raster = (WritableRaster) writeImage.getData();
raster.setPixels(0,0,width,height,pixels);
writeImage.setData(raster);
ImageIO.write(writeImage, "png", outputfile);
} catch (IOException e) {
}
}
}
It's not clear which of the below is triggering your error. This
File EnImage = new File("encrypted.png");
will read from the current directory, which is not necessarily the same directory as that your jar file is in.
This
image = ImageIO.read(getClass().getResourceAsStream("lena.png"));
will read from the directory in the jar file that your class is in. Note that you're reading from the jar file, not the directory.
Given the above code, I would:
determine or explicitly specify the working directory for the File() operations. Your working directory is the one you invoke java from, and this may differ within/without the IDE
package the lena.png as a resource within your .jar file.