Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.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/230.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 将图像加载到imageview会导致;我/编舞:跳过了139帧!应用程序可能在其主线程上做了太多工作。”;错误_Java_Android_Multithreading_Image_Performance - Fatal编程技术网

Java 将图像加载到imageview会导致;我/编舞:跳过了139帧!应用程序可能在其主线程上做了太多工作。”;错误

Java 将图像加载到imageview会导致;我/编舞:跳过了139帧!应用程序可能在其主线程上做了太多工作。”;错误,java,android,multithreading,image,performance,Java,Android,Multithreading,Image,Performance,我正在使用照相机拍摄一张照片,然后使用该图像将其显示在我的应用程序片段中。图像将加载,但会导致大量性能问题,并导致应用程序在图像显示在屏幕上时运行非常糟糕。我已经尝试实现线程来解决这个问题,但它仍然在发生。在logcat中,我收到了“I/Choreographer:跳过175帧!应用程序可能在其主线程上做了太多工作”的警告。如能帮助解决此问题,我们将不胜感激 我在OnActivityResults方法中执行线程,因为这是显示图像的地方 相机碎片类 public class Camera_Frag

我正在使用照相机拍摄一张照片,然后使用该图像将其显示在我的应用程序片段中。图像将加载,但会导致大量性能问题,并导致应用程序在图像显示在屏幕上时运行非常糟糕。我已经尝试实现线程来解决这个问题,但它仍然在发生。在logcat中,我收到了“I/Choreographer:跳过175帧!应用程序可能在其主线程上做了太多工作”的警告。如能帮助解决此问题,我们将不胜感激

我在OnActivityResults方法中执行线程,因为这是显示图像的地方

相机碎片类

public class Camera_Fragment extends Fragment {

private static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 0;
private ImageView imageView;

public Camera_Fragment() {
    // Required empty public constructor
}

private String pictureImagePath = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = timeStamp + ".png";

    File mydir = getExternalStoragePublicDirectory("app image folder"); //Creating an internal dir;
    if (!mydir.exists())
    {

        {
            mydir.mkdirs();
        }
    }
    isReadPermissionGranted();
    pictureImagePath = mydir.getAbsolutePath() + "/" + imageFileName;
    File file = new File(pictureImagePath);
    Uri outputFileUri = Uri.fromFile(file);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    Fragment frag = this;
    frag.getActivity();
    /** Pass your fragment reference **/
    frag.startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); // REQUEST_IMAGE_CAPTURE = 12345

}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View rootView = inflater.inflate(R.layout.camera_layout_fragment, container, false);

    imageView = (ImageView) rootView.findViewById(R.id.imageView1);
    return rootView;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1) {
        final File imgFile = new  File(pictureImagePath);
        if(imgFile.exists()){

            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    final Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                    imageView.setImageBitmap(myBitmap);
                }
            });
        }
    }
}

public  boolean isStoragePermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(this.getContext(),android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
        } else {

            Log.v(TAG,"Permission is revoked");
            ActivityCompat.requestPermissions(this.getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
            return false;
        }
    }
    else { //permission is automatically granted on sdk<23 upon installation
        Log.v(TAG,"Permission is granted");
        return true;
    }
}


public  boolean isReadPermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(this.getContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
        } else {

            Log.v(TAG,"Permission is revoked");
            ActivityCompat.requestPermissions(this.getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
            return false;
        }
    }
    else { //permission is automatically granted on sdk<23 upon installation
        Log.v(TAG,"Permission is granted");
        return true;
    }
}
   }
有,可以异步加载您的图像。请考虑使用一个,如毕加索。


如果您希望自己执行此操作,则需要安排在后台线程上执行
decodeFile()
,然后在主应用程序(UI)线程上调用
setImageBitmap()

谢谢你,我现在正在研究毕加索,希望能让事情变得更简单:)
    04-16 22:06:44.023 5043-5207/com.keith.draco.crecheapp I/OpenGLRenderer:               
    Initialized EGL, version 1.4
    04-16 22:06:44.252 5043-5043/com.keith.draco.crecheapp W/art: Before 
    Android 4.1, method int 
    android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, 
    boolean) would have incorrectly overridden the package-private method in 
    android.widget.ListView
    04-16 22:06:48.553 5043-5207/com.keith.draco.crecheapp D/OpenGLRenderer: 
    endAllActiveAnimators on 0xb90e4e30 (RippleDrawable) with handle 
    0xb90e6150
    04-16 22:06:49.345 5043-5043/com.keith.draco.crecheapp W/PathParser: 
    Points are too far apart 4.000000596046461
    04-16 22:06:49.348 5043-5043/com.keith.draco.crecheapp W/PathParser: 
    Points are too far apart 4.000000596046461
    04-16 22:06:50.529 5043-5043/com.keith.draco.crecheapp W/PathParser: 
    Points are too far apart 4.000000596046461
    04-16 22:06:50.531 5043-5043/com.keith.draco.crecheapp W/PathParser: 
    Points are too far apart 4.000000596046461
    04-16 22:06:50.546 5043-5043/com.keith.draco.crecheapp V/ContentValues:  
    Permission is granted
    04-16 22:07:05.917 5043-5043/com.keith.draco.crecheapp       
    I/ListPopupWindow: Could not find method setEpicenterBounds(Rect) on 
    PopupWindow. Oh well.
    04-16 22:07:08.389 5043-5043/com.keith.draco.crecheapp I/Choreographer: 
    Skipped 142 frames!  The application may be doing too much work on its 
    main thread.
    04-16 22:07:10.764 5043-5043/com.keith.draco.crecheapp I/Choreographer: 
    Skipped 138 frames!  The application may be doing too much work on its 
    main thread.
    04-16 22:07:15.869 5043-5043/com.keith.draco.crecheapp I/Choreographer: 
    Skipped 135 frames!  The application may be doing too much work on its 
    main thread.