Bahram
Bahram

Reputation: 1652

Drawing text on bitmap in android

I am drawing a text on bitmap in android application and then i am saving it in sd-card. the image getting saved but there is no text, i mean it seems that there some problem in drawtext, this is my code

Bitmap bitmap = Bitmap.createBitmap(370, 177, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    c.drawColor(0xffffffff);
    Paint p = new Paint();
    p.setColor(R.color.black);
    //p.setStyle(Style.FILL);
    //p.setStrokeWidth(40.0f);
    //p.setTextSize(40.0f);
    //p.setTextAlign(Align.RIGHT);
    c.drawText("Some text", 70, 77, p);
    //c.save();

    try {
        FileOutputStream fos = new FileOutputStream(myfile);
        bitmap.compress(CompressFormat.PNG, 90, fos);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    bitmap.recycle();

am i forget something or what's wrong with this code ?

Upvotes: 0

Views: 1230

Answers (1)

Vladimir Mironov
Vladimir Mironov

Reputation: 30874

R.color.black is not a real color but just a reference to a color value. Replace it with Color.BLACK or getResources().getColor(R.color.black)

p.setColor(Color.BLACK);

OR

p.setColor(getResources().getColor(R.color.black));

Upvotes: 4

Related Questions