Hi, i'm trying to render text by creating a canvas for a bitmap with a transparent background and then drawing onto the canvas. When i save the resulting bitmap however, the resulting image doesn't have a transparent background but a black one. Can it have anything to do with the config i set for the bitmap? Here is the code i use to draw and save as png:
Any help would be appreciated.
Tnx.
Code:
public class TextToImage3 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int height = display.getHeight(); // not exactly correct
int width = display.getWidth(); // not exactly correct
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
Canvas c = new Canvas(bitmap);
c.drawColor(Color.TRANSPARENT);
Paint paint = new Paint();
paint.setTextSize(60);
paint.setColor(Color.WHITE);
c.drawText("Test", 100, 300, paint);
ImageView iv = new ImageView(this);
iv.setImageBitmap(bitmap);
setContentView(iv);
try{
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
File f = new File(root, "TAG_test.png");
FileOutputStream out = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Any help would be appreciated.
Tnx.