简体   繁体   中英

Change ImageView (Bitmap) in ViewPager

I have an Camera Activity which wraping a ViewPager with a Custom Adapter. When the user takes a picture I load the pic into the viewPager, so the user can swipe throught pictures (like Google Camera app). I would like to replace the already taken picture (Bitmap in ImageView) with a filtered one (like Instagram).

How can I replace / swap two ImageView in ViewPager ? I know this is a dummy question, but I had found several solutions, and non of them are working.

Use : ImageView imageView1= ((ImageView) viewPager.findViewById (R.id.imageView1));

For more image processing effects/filters you can go through:

Catalano Framework, It works in Desktop as Android.

http://code.google.com/p/catalano-framework/

Example:

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();

or if you dont want to use any libraries, take a look at Android: Image Processing it has fantastic image processing example

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM