Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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
Java 在画布上定位位图_Java_Android - Fatal编程技术网

Java 在画布上定位位图

Java 在画布上定位位图,java,android,Java,Android,原谅我,如果这是一个简单的问题,但我被卡住了。 我正试图将图像的位置设置到屏幕左侧一定的距离-150。 它适用于正数,但不适用于负数。 我在画布上绘制它,因为我将在稍后向生成的位图结果中添加更多图像。 这是我的密码 Bitmap image2=resizedbitmap; result = Bitmap.createBitmap(image2.getWidth(), image2.getHeight(), ` `Bitmap.Config.ARG

原谅我,如果这是一个简单的问题,但我被卡住了。 我正试图将图像的位置设置到屏幕左侧一定的距离-150。 它适用于正数,但不适用于负数。 我在画布上绘制它,因为我将在稍后向生成的位图结果中添加更多图像。 这是我的密码

     Bitmap image2=resizedbitmap;

     result = Bitmap.createBitmap(image2.getWidth(), image2.getHeight(),             `   `Bitmap.Config.ARGB_8888);        
     canvas = new Canvas(result);//Create the canvas to an image                
     srcRect = new Rect(-150, 0, result.getWidth(), result.getHeight());//does not work with negative numbers
     destRect = new Rect(srcRect);
     destRect.offset(0, 0);//if negative cuts the image
     canvas.drawBitmap(image2, srcRect, destRect, null);
我错过什么了吗?谢谢你的帮助。
许多tnx预先使用了它,请参见此处

新矩形0,0,宽度,高度不是在左上角吗?是的,但我想将其设置为新矩形150,0。。对于i.e.new Rect150,0,它在屏幕外将其设置为右侧,而不是-150:因此,对于-150,它应该在屏幕外的左侧设置为150个单位?因为对于+150,它将位图放置在右侧,我认为它应该在左侧设置为-150时执行相同的操作,但这是目前的问题。所以,是的,在屏幕外的左侧