android when trying drawing a text on it using canvas i get an error
-
27-06-2021 - |
سؤال
I tried drawing text on an image, but it doesn't work. Here is my code:
ImageView image = (ImageView) findViewById(R.id.imageView1);
Uri uri = Uri.parse("android.resource://mms.first/"+R.drawable.girl);
Bitmap bitmap;
try {
ContentResolver cr = getContentResolver();
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, uri);
//drawTextImage(bitmap);
Canvas c = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setTextSize(20);
c.drawText("Golden Stag", 30, 200, paint);
image.setImageBitmap(bitmap);
المحلول
This is the code:
Bitmap bitmap;
Resources resx = getResources();
bitmap = BitmapFactory.decodeResource(resx, R.drawable.girl);
Canvas canvas = new Canvas(bitmap.copy(Bitmap.Config.ARGB_8888, true));
لا تنتمي إلى StackOverflow