I am new to android,I developed one sample application which load the image from sd card and display as a bitmap image using image view controll. Now i want to modify my application like load the bmp from byte array i have the raw image ,width and height ,do any one have sample for this?
            Asked
            
        
        
            Active
            
        
            Viewed 2,941 times
        
    3 Answers
5
            Use below Code for Convert Byte Array to Bitmap and display this bitmap into ImageView.
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
and see below SO link for more information.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Dipak Keshariya
        
- 22,193
- 18
- 76
- 128
0
            
            
        if your image is in Drawable folder try this code
    Drawable drawable= getResources().getDrawable(R.drawable.yourimage);
    //Type cast to BitmapDrawable
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
    //Write a compressed version of the bitmap to the specified outputstream via compress method.    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    byte[] buffer  = stream.toByteArray();
 
    
    
        Renjith
        
- 5,783
- 9
- 31
- 42
 
    
    
        NARESH REDDY
        
- 682
- 4
- 11
