Reputation: 1011
I have a pic in res/drawable-hpdi/pic.jpg, then i have a alert box that should display the image height width size name and extension, i just cant figure out how to get it act like a file and get its size etc.
Bitmap bMap = BitmapFactory.decodeResource(getResources(),
R.drawable.pic);
File file=new File("res/drawable-hdpi/pic.jpg");
long length = file.length();
if (!file.exists()) {
length = -1;
}
imgInfo = "Height: " + bMap.getWidth() + "\n" + "Width: " + bMap.getHeight()
+ "\n" +"Size: " + length;
i get the height and width i cant get the rest can someone help me ?
Upvotes: 2
Views: 728
Reputation: 646
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileOutputStream fo = null;
bMap.compress(Bitmap.CompressFormat.JPEG, 40, baos);
File dst = new File (photoName + ".jpg");
try
{
dst.createNewFile();
//write the bytes in file
fo = new FileOutputStream(dst);
fo.write(baos.toByteArray());
}
catch (IOException e)
{
Log.e("Photo Convert","Error creating file. Check: "+dst, e);
}
After that, you'll be able to check file dst
size and other stuff. Hope it'll help
Upvotes: 1