vendredi 10 avril 2015

File format without random number suffex

I am making an android application in which i am saving my image in my preffered Folder in Storage "SampleApp". When i am using this method it is saving every new image with random number generated and makes alot of images in my folder. I just want to use it without any random generated number. This method is making random generated number with my image name File.createTempFile. Please help me out here



public static String saveToInternalStorage(Bitmap bitmapImage, Context ctx) throws IOException{
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Murgency");

// File image = new File(directory,"murgcy.jpg");

File image = File.createTempFile("murgcy", /* prefix */".jpg",/* suffix */directory /* directory */);
if (!image.mkdirs()) {
Log.e("Utils", "Directory not created");
}

FileOutputStream fos = null;
try {
// fos = openFileOutput(filename, Context.MODE_PRIVATE);

fos = new FileOutputStream(image);

// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return image.getPath();
}




Aucun commentaire:

Enregistrer un commentaire