Zoroastro
Zoroastro

Reputation: 47

Draw background on a bitmap where i'm going to draw a view that i'm going to export to a file

I'm exporting my view into a file.

My problem is that I'm using Holo Light theme but the file exported has a dark background.

The code:

Bitmap b = Bitmap.createBitmap(totalWidth, totalHeight, Bitmap.Config.ARGB_8888);
Canvas mCanvas = new Canvas(b);
miVista.draw(mCanvas);          
FileOutputStream fos = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos); 

I've tried a lot of things to paint it in another color than black like drawcolor, setpixels, etc, but I can't find the correct answer to my problem.

Link to the picture with what you can see in the terminal.

Link to the exported picture

Upvotes: 0

Views: 979

Answers (2)

Axarydax
Axarydax

Reputation: 16623

Clear the canvas for example with

mCanvas.drawColor(Color.WHITE); 

then it will have white background. What kind of background do you expect?

Upvotes: 1

Zoroastro
Zoroastro

Reputation: 47

I've found the solution in this other post: Convert view to bitmaps...

Bitmap b = Bitmap.createBitmap(totalWidth, totalHeight, Bitmap.Config.ARGB_8888);
Canvas mCanvas = new Canvas(b);
Drawable bgDrawable =miVista.getBackground();
if (bgDrawable!=null) 
    bgDrawable.draw(mCanvas);
else 
    mCanvas.drawColor(Color.WHITE);
miVista.draw(mCanvas);  

The solution it's to use a Drawable object...

Upvotes: 0

Related Questions