Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color/touch location is incorrect when compiled for SdkVersion 28 and above #9

Open
mgood7123 opened this issue Apr 5, 2020 · 1 comment
Assignees

Comments

@mgood7123
Copy link

No description provided.

@mgood7123
Copy link
Author

mgood7123 commented Apr 5, 2020

this seems to fix it and produces the correct pixel color

https://stackoverflow.com/a/46377322

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final View targetView = findViewById(R.id.colorSample);
        targetView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent ev) {
                // TODO Auto-generated method stub
                ImageView img = (ImageView) v;

                final int evX = (int) ev.getX();
                final int evY = (int) ev.getY();

                img.setDrawingCacheEnabled(true);
                Bitmap imgbmp = Bitmap.createBitmap(img.getDrawingCache());
                img.setDrawingCacheEnabled(false);

                try {
                    int pxl = imgbmp.getPixel(evX, evY);

                    findViewById(R.id.colorSlot).setBackgroundColor(pxl);

                }catch (Exception ignore){
                }
                imgbmp.recycle();

                return true;
            }
        });
//        setUp();
    }

mgood7123 added a commit to mgood7123/profile-image-extractor that referenced this issue Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants