安卓:我怎样才能得到一个形象,是在KB,名和扩展名绘制它的大小 [英] Android : How can i get a image that is in drawable its size in KB, name and extension

查看:104
本文介绍了安卓:我怎样才能得到一个形象,是在KB,名和扩展名绘制它的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在水库一个PIC /绘制-HPDI / pic.jpg,那我也应该显示图像高宽尺寸名和扩展名,我只是无法弄清楚如何得到它像一个文件一个警告框和得到它的大小等。

 位图BMAP = BitmapFactory.de codeResource(getResources()
            R.drawable.pic);

    档案文件=新的文件(RES /绘制,华电国际/ pic.jpg);
    长长度= file.length();
    如果(!file.exists()){
        长度= -1;
    }
    imgInfo =高度:+ bMap.getWidth()+\ N+宽:+ bMap.getHeight()
            +\ N+尺寸:+长;
 

我得到的高度和宽度,我不能得到休息有人可以帮助我?

解决方案

  ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
    FileOutputStream中FO = NULL;

    bMap.com preSS(Bitmap.Com pressFormat.JPEG,40,BAOS);


    文件DST =新的文件(photoName +名.jpg);
    尝试
    {
    dst.createNewFile();
    //写在文件中的字节
    FO =新的FileOutputStream(DST);
    fo.write(baos.toByteArray());
    }
    赶上(IOException异常E)
    {
        Log.e(照片转换,错误创建文件检查:+ DST,E);
    }
 

在这之后,你就可以检查文件 DST 尺寸和其他的东西。希望这会帮助

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 ?

解决方案

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

这篇关于安卓:我怎样才能得到一个形象,是在KB,名和扩展名绘制它的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆