android - 如何获取viewPager上显示的当前图像的id

标签 android android-viewpager drawable

@Override
        public void onClick(View v) {
            try {
                //Write fileObject tag = imageView.getTag();                  

                //Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.c);

            Bitmap bmp= BitmapFactory.decodeResource(getResources(),v.getResources().getResourceName((Integer)v.getTag()));


                String filename = "bitmap.png";
                FileOutputStream stream = getApplicationContext().openFileOutput(filename, Context.MODE_PRIVATE);
                bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

                //Cleanup
                stream.close();
                bmp.recycle();

我想从 viewPager 添加图像 ID 而不是 R.drawable.img1,请问有什么帮助吗? 我已经编辑了我的问题,而不是从可绘制的图像中获取图像,我需要在 viewPager 上获取当前图像。我该怎么做?

最佳答案

我找到了解决办法

位图 bmp=getBitmapFromView(viewPager.getChildAt(1));

我得到了我的解决方案,感谢您的所有反馈

关于android - 如何获取viewPager上显示的当前图像的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26582208/

相关文章:

android - 如何知道图库小部件何时停止滚动?

android - ViewPager 离屏页面限制

android - Drawable setAlpha 不适用于 android 4.4.2

android - 使用适用于 Android 的 google places api 网络服务搜索附近的特定地点

java - 如何仅从 Firestore 获取最新更新的数据?

android - 如何使用在 fragment 之间设置动画的共享元素过渡

android - 启动画面错误 : android. content.res.Resources$NotFoundException: Drawable

android - 更改基于设备的位图大小 Android Studio

android - 错误 :(34) No resource identifier found for attribute 'srcCompat' in package 'com.hackerinside.jaisonjoseph.radioplanet'

android - 使用 Tabs 将 ViewPager 中的 ListFragment 替换为 Fragment