Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建位图周围的矩形_Android_Bitmap - Fatal编程技术网

Android 创建位图周围的矩形

Android 创建位图周围的矩形,android,bitmap,Android,Bitmap,我有一个10*15大小的位图现在我想从这个现有位图创建一个大小为20*30的位图,但是增加的区域应该是透明的,位图不应该被转换/缩放。创建一个新的位图即20x30,创建一个画布来保存该位图,然后画布.drawBitmap()将您的10x15位图放入其中。创建一个新的20x30的位图,创建一个画布来容纳该位图,然后画布.drawBitmap()将您的10x15位图放入其中。使用以下方法创建第一个位图: Bitmap b=b.createBitmap (Bitmap source, int x, i

我有一个10*15大小的位图现在我想从这个现有位图创建一个大小为20*30的位图,但是增加的区域应该是透明的,位图不应该被转换/缩放。

创建一个新的
位图
即20x30,创建一个
画布
来保存该位图,然后
画布.drawBitmap()
将您的10x15位图放入其中。

创建一个新的20x30的
位图,创建一个
画布来容纳该位图,然后
画布.drawBitmap()
将您的10x15位图放入其中。

使用以下方法创建第一个位图:

Bitmap b=b.createBitmap (Bitmap source, int x, int y, int width, int height);

给出您的高度和宽度以及正确的x和y值

使用以下方法创建第一个位图:

Bitmap b=b.createBitmap (Bitmap source, int x, int y, int width, int height);

给出你的高度和宽度以及适当的x和y值

我没听清你的问题。。。。 标题是“围绕位图绘制矩形”,但没有关于矩形的详细说明。 如果您想要一个矩形,那么可以按如下方式进行

RectF rect = new RectF(x,y,x+width,y+height);  
canvas.drawRect(rect, paint);  

绘制位图参考其他答案…

我没有收到你的问题。。。。
Bitmap b = Bitmap.createBitmap(
    yourBitmap,
    xMarginYouWant,
    yMarginYouWant,
    yourBitmap.getWidth() + xMarginYouWant * 2,
    yourBitmap.getHeight() + yMarginYouWant * 2
);
标题是“围绕位图绘制矩形”,但没有关于矩形的详细说明。 如果您想要一个矩形,那么可以按如下方式进行

RectF rect = new RectF(x,y,x+width,y+height);  
canvas.drawRect(rect, paint);  
绘制位图参考其他答案

Bitmap b = Bitmap.createBitmap(
    yourBitmap,
    xMarginYouWant,
    yMarginYouWant,
    yourBitmap.getWidth() + xMarginYouWant * 2,
    yourBitmap.getHeight() + yMarginYouWant * 2
);