在Android中运行时在图像周围添加彩色边框
我可以在运行时向图像(不是图像视图)添加彩色边框或边框吗。如果是,如何做到这一点。请引导我。试试这样的方法:在Android中运行时在图像周围添加彩色边框,android,image,frame,Android,Image,Frame,我可以在运行时向图像(不是图像视图)添加彩色边框或边框吗。如果是,如何做到这一点。请引导我。试试这样的方法: Bitmap someImage; int width = someImage.getWidth(); int height = someImage.getHeight(); RectF targetRect = new RectF(3, 3, width - 3, height - 3); Bitmap dest = Bitmap.createBitmap(width +
Bitmap someImage;
int width = someImage.getWidth();
int height = someImage.getHeight();
RectF targetRect = new RectF(3, 3, width - 3, height - 3);
Bitmap dest = Bitmap.createBitmap(width + 20, height + 20,someImage.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawColor(Color.RED);
canvas.drawBitmap(someImage, null, targetRect, null);
只需根据需要更改填充和颜色
希望有帮助!:) 您可以使用
android:background=“path”
将该图像作为只应具有帧边框的帧
而中心部分应该是透明和透明的
您的图像应指定为
androd:src=“path”
而且还要垫上垫子
i、 e
android:padding=“3dp”
填充可能高达5dp,也可能取决于边框的厚度
所以看起来像
<ImageView
android:id="@+id/activity_test_img_signs"
android:layout_width="@dimen/imagesize"
android:layout_height="@dimen/imagesize"
android:background="@drawable/img_border_new"
android:contentDescription="@string/app_name"
android:padding="@dimen/padding_small"
android:scaleType="fitXY"
android:src="@drawable/q101"
android:visibility="invisible" />
ImageView imageViewMyGraphicalImageElement= (ImageView) findViewById(R.id.imageViewMyGraphicalImageElement);
imageViewMyGraphicalImageElement.setImageBitmap(sBitmap);
朋友…非常感谢你在所有建议之间埋藏了这颗宝石…我尝试了几乎所有的方法,但除了这个:)我浪费了3个小时试图在imageview周围建立边界,直到找到这篇文章