GestureImageView goes blank when trying to set bitmap from camera programatically

醉酒当歌 提交于 2019-12-13 21:53:29

问题


I am using: https://github.com/jasonpolites/gesture-imageview

  • on load of the app, it has a placeholder image in a GestureImageView that pinch/zooms appropriately. I have a button that when clicks fires a camera intent, saves the file, and then I wish to set that image to be the source bitmap used in the gestureimageview.

    GestureImageView imageView = (GestureImageView) findViewById(R.id.imageViewOne);

    ContentResolver cr = getContentResolver();
    
    getContentResolver().notifyChange(imageUriOne, null);
    
    
                    try {
    Bitmap mybitmap =  android.provider.MediaStore.Images.Media.getBitmap(cr, imageUriOne);
    
     imageView.setImageBitmap(mybitmap);
    

    }

For a normal imageview, that works. But for the GestureImageView, the image stays as the original once returned from the camera intent, and if touched disappears.

To check it's not the bitmap that's the problem, I tried

int idTwo=getResources().getIdentifier("com.jazz.test1:drawable/second_photo", null, null);

imageView.setImageResource(idTwo);

I.e. set the imageview to an existing resource, but this has the same problem.

If I call that setImageResource code before the intent, it does work.

Any ideas how to debug? There are no errors in the logs.


回答1:


Resolution is here:

https://github.com/jasonpolites/gesture-imageview/issues/21

  • hadn't noticed it when I initially looked at the github issues.



回答2:


You have to replace your initMethod function. With this code it will work properly (GestureImageView.java file in com.polites.android package).

protected void initImage() {
        if (this.drawable != null) {
            this.drawable.setAlpha(alpha);
            this.drawable.setFilterBitmap(true);
            if (colorFilter != null) {
                this.drawable.setColorFilter(colorFilter);
            }
            // Keppel.Cao
            layout = false;
            startingScale = -1.0f;
        }

        if (!layout) {
            requestLayout();
            // Keppel.Cao
            // redraw();
            reset();
        }
}

Like Dave said. More you can find here Issue 21



来源:https://stackoverflow.com/questions/13866950/gestureimageview-goes-blank-when-trying-to-set-bitmap-from-camera-programaticall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!