SQLite captured image with black background in ImageView

0

In my application, I need to capture an image that is on a SQLite base in the byte (Blob) format and then convert it to Bitmap to display it in a ImageView .

My problem is that the space of ImageView that is left horizontal is always black.

layout.xml

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1"> 

    <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/imageView1" 
        android:layout_weight="1" 
        android:src="@drawable/foto_default" /> 

</LinearLayout>

Conversion Method:

private void setImage(){
    byte[] outImage = lista.get(position).getFoto(); 
    ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage); 
    Bitmap imagemConvertida = BitmapFactory.decodeStream(imageStream); 
    foto.setImageBitmap(imagemConvertida);
}

Can you help me?

    
asked by anonymous 09.06.2015 / 18:36

1 answer

0

I was able to solve my problem. The problem was in the code that converts the Bitmap image to bytes. I was recording the image as JPEG and could not. The image had to be recorded as PNG. Here is the corrected code:

imageView.buildDrawingCache(); Bitmap imagemDoImageview = imageView.getDrawingCache(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); imagemDoImageview.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] imageInByte = stream.toByteArray();

    
09.06.2015 / 22:13