Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Android 在ViewPager中更改图像视图(位图)_Android_Replace_Bitmap_Android Viewpager - Fatal编程技术网

Android 在ViewPager中更改图像视图(位图)

Android 在ViewPager中更改图像视图(位图),android,replace,bitmap,android-viewpager,Android,Replace,Bitmap,Android Viewpager,我有一个摄像头活动,它用一个自定义适配器包装一个ViewPager。当用户拍照时,我将图片加载到viewPager中,这样用户就可以浏览图片(比如谷歌相机应用程序)。我想将已经拍摄的照片(ImageView中的位图)替换为经过过滤的照片(如Instagram) 如何替换/交换ViewPager中的两个ImageView? 我知道这是一个虚拟的问题,但我已经找到了几个解决方案,其中没有一个是有效的 使用:ImageView-imageView1=((ImageView)viewPager.find

我有一个摄像头活动,它用一个自定义适配器包装一个ViewPager。当用户拍照时,我将图片加载到viewPager中,这样用户就可以浏览图片(比如谷歌相机应用程序)。我想将已经拍摄的照片(ImageView中的位图)替换为经过过滤的照片(如Instagram)

如何替换/交换ViewPager中的两个ImageView?
我知道这是一个虚拟的问题,但我已经找到了几个解决方案,其中没有一个是有效的

使用:
ImageView-imageView1=((ImageView)viewPager.findviewbyd(R.id.imageView1))

有关更多图像处理效果/过滤器,您可以浏览:

Catalano框架,与Android一样在桌面上工作

例如:

FastBitmap fb = new FastBitmap(bitmap);
//If you want to apply threshold
Grayscale g = new Grayscale();
g.applyInPlace(fb);
Threshold t = new Threshold(120);
t.applyInPlace(fb);
bitmap = fb.toBitmap();
或者如果你不想使用任何库, 看看Android:图像处理 它有奇妙的图像处理例子

public static Bitmap doGreyscale(Bitmap src) {
    // constant factors
    final double GS_RED = 0.299;
    final double GS_GREEN = 0.587;
    final double GS_BLUE = 0.114;

    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    // pixel information
    int A, R, G, B;
    int pixel;

    // get image size
    int width = src.getWidth();
    int height = src.getHeight();

    // scan through every single pixel
    for(int x = 0; x < width; ++x) {
        for(int y = 0; y < height; ++y) {
            // get one pixel color
            pixel = src.getPixel(x, y);
            // retrieve color of all channels
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            // take conversion up to one single value
            R = G = B = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);
            // set new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}
公共静态位图doGreyscale(位图src){
//常数因子
最终双GS_红=0.299;
最终双GS_绿=0.587;
最终双GS_蓝=0.114;
//创建输出位图
位图bmOut=Bitmap.createBitmap(src.getWidth()、src.getHeight()、src.getConfig());
//像素信息
int A,R,G,B;
整数像素;
//获取图像大小
int width=src.getWidth();
int height=src.getHeight();
//扫描每一个像素
对于(int x=0;x
对不起,我弄错了。我想替换ViewPager中包装的ImageView中的位图。是否尝试使用
ImageView.setImageBitmap(bImage)当然,我的问题是用过滤过的图像(深褐色、黑白、模糊等)替换viewpager中的图像。好的,非常感谢Sagar!但我的问题是如何替换ViewPager中的ImageView?我可以对图像应用过滤器,这不是问题,我的问题是将过滤后的图像加载回viewpager,以便向用户显示它。请尝试
ImageView imageView1=((ImageView)viewpager.findViewById(R.id.imageView1))然后尝试更改图像位图