在Android的图片视图上添加文本水印可以通过以下步骤实现:
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.your_image);
Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.your_image);
Bitmap watermarkBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(watermarkBitmap);
canvas.drawBitmap(originalBitmap, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(50);
paint.setAntiAlias(true);
canvas.drawText("Your Watermark Text", x, y, paint);
其中,x和y是文本水印的起始坐标。
imageView.setImageBitmap(watermarkBitmap);
完整的代码示例:
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.your_image);
Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.your_image);
Bitmap watermarkBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(watermarkBitmap);
canvas.drawBitmap(originalBitmap, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(50);
paint.setAntiAlias(true);
canvas.drawText("Your Watermark Text", x, y, paint);
imageView.setImageBitmap(watermarkBitmap);
这样,你就可以在Android的图片视图上成功添加文本水印了。
关于腾讯云相关产品和产品介绍链接地址,由于要求不能提及具体品牌商,建议你参考腾讯云的官方文档和开发者社区,以获取更多关于云计算和移动开发的相关信息和产品推荐。
领取专属 10元无门槛券
手把手带您无忧上云