错误:(191,78)错误:在android中找不到符号变量ARGB_8888

错误:(191,78)错误:在android中找不到符号变量ARGB_8888,android,image,bitmap,Android,Image,Bitmap,在“编辑员工”活动中,有一个ImageView。ImageView将显示从MySQL获取的图像 在imageView下面,它有一个更改图片按钮,供用户更改图片 public void activeGallery() { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

在“编辑员工”活动中,有一个ImageView。ImageView将显示从MySQL获取的图像

在imageView下面,它有一个更改图片按钮,供用户更改图片

 public void activeGallery()
    {
        Intent intent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, RESULT_LOAD_IMAGE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case RESULT_LOAD_IMAGE:
                if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK & null != data) {
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver()
                            .query(selectedImage, filePathColumn, null, null,
                                    null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();
                    Bitmap a = (BitmapFactory.decodeFile(picturePath));
                    photo = scaleBitmap(a, 200, 150);
                    image1.setImageBitmap(photo);
                }

  public Bitmap scaleBitmap(Bitmap bitmap,int newWidth,int newHeight) {
        Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888);

        float ratioX = newWidth / (float) bitmap.getWidth();
        float ratioY = newHeight / (float) bitmap.getHeight();
        float middleX = newWidth / 2.0f;
        float middleY = newHeight / 2.0f;

        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);

        Canvas canvas = new Canvas(scaledBitmap);
        canvas.setMatrix(scaleMatrix);
        canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));

        return scaledBitmap;
    }
为了从MySQL获取图像,我使用这个库

import com.example.project.myapplication.Handler.Config;
但是,无法解决scaleBitmap中的Config.ARGB_8888。我改成 导入android.graphics.Bitmap.Config;,但无法解析showStaff中的Config.TAG_图像


我怎样才能解决这个问题?谢谢,您收到了错误,因为您的配置类没有ARGB_8888字段

您可以将类名更改为Config以外的名称,以便在导入时同时使用它们,也可以使用

比如:

import android.graphics.Bitmap.Config;
// The rest of your code
// ...
// And make a call somewhat like this:
Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, android.graphics.Bitmap.Config.ARGB_8888);
但我认为将Config类重命名为类似Configs的东西会更快,以避免名称空间冲突


阅读有关类和名称空间的更多信息,也请检查。

import android.graphics.Bitmap.config;不能用大写字母C,对不起,我的错。它是Config,不是Config。如果我使用android.graphics.Bitmap.Config,我需要重命名我的Config类吗?这是一种选择。重命名为类似Configs的名称,以避免名称空间冲突。我已经编辑了答案,请看一看。两种方法都会奏效,选择一种你觉得最适合你的方法。
import android.graphics.Bitmap.Config;
// The rest of your code
// ...
// And make a call somewhat like this:
Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, android.graphics.Bitmap.Config.ARGB_8888);