Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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 Android:从位图裁剪位图并设置为ImageView src_Java_Android_Bitmap - Fatal编程技术网

Java Android:从位图裁剪位图并设置为ImageView src

Java Android:从位图裁剪位图并设置为ImageView src,java,android,bitmap,Java,Android,Bitmap,我试图从精灵表中裁剪精灵,但是裁剪的图像不是我指定的图像的一部分 精灵表包含大小为32 x 32 px的精灵,因此第一个精灵应在水平方向上为0到32像素,垂直方向上为0到32像素,假设最左上角的像素为[0,0] Bitmap spritesheet = BitmapFactory.decodeResource(getResources(), R.drawable.spritesheet_32x32); Bitmap sprite = Bitmap.createBitmap(spritesheet

我试图从精灵表中裁剪精灵,但是裁剪的图像不是我指定的图像的一部分

精灵表包含大小为32 x 32 px的精灵,因此第一个精灵应在水平方向上为0到32像素,垂直方向上为0到32像素,假设最左上角的像素为[0,0]

Bitmap spritesheet = BitmapFactory.decodeResource(getResources(), R.drawable.spritesheet_32x32);
Bitmap sprite = Bitmap.createBitmap(spritesheet, 0, 0, 32, 32);
ImageView只是一个普通的ImageView,没有设置src、宽度或高度

ImageView view = (ImageView)findViewById(R.id.player1);
view.setImageBitmap(sprite);
但显示的图像只是第一个精灵的一小部分。 我监督什么?是view.setImageBitmapsprite;正确的方法是什么?在设置位图之前,ImageView是否需要固定宽度和高度

编辑:也许我应该更清楚我的布局。线性布局上有两个图像视图。以下是XML:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="false">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX="-1"
        android:id="@+id/player1"
        android:layout_weight="1"
        android:layout_gravity="center_vertical" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/player2"
        android:layout_weight="1"
        android:layout_gravity="center_vertical" />
</LinearLayout>
调用该方法

Bitmap bmp = ImageResizer.decodeSampledBitmapFromFile(new  File(filePath).getAbsolutePath(), 512, 342);               
我还没有尝试过,但是下面的方法可能会通过方法参数
imageView.getWidth、imageView.getHeight

是否必须使用此方法设置imageView的高度和宽度?现在我只是传递精灵表的原始尺寸,结果看起来是一样的。
Bitmap bmp = ImageResizer.decodeSampledBitmapFromFile(new  File(filePath).getAbsolutePath(), 512, 342);