How to get byte array from imageview

来源:互联网 发布:苹果5支持联通4g网络吗 编辑:程序博客网 时间:2024/05/01 03:04
ImageView iv = (ImageView) findViewById(R.id.splashImageView);    Drawable d =iv.getBackground();    BitmapDrawable bitDw = ((BitmapDrawable) d);    Bitmap bitmap = bitDw.getBitmap();    System.out.println(".....d....."+d);    System.out.println("...bitDw...."+bitDw);    System.out.println("....bitmap...."+bitmap);    ByteArrayOutputStream stream = new ByteArrayOutputStream();    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);    byte[] imageInByte = stream.toByteArray();

store byte[] in database

ContentValues cv=new ContentValues();        cv.put(CHUNK, buffer);       //CHUNK blob type field of your table        long rawId=database.insert(TABLE, null, cv); //TABLE table name

retrieve image from byte array[]

public static Bitmap convertByteArrayToBitmap(            byte[] byteArrayToBeCOnvertedIntoBitMap) {        bitMapImage = BitmapFactory.decodeByteArray(                byteArrayToBeCOnvertedIntoBitMap, 0,                byteArrayToBeCOnvertedIntoBitMap.length);        return bitMapImage;    }
原创粉丝点击