[英]Change ImageView (Bitmap) in ViewPager
我有一個Camera Activity,它用自定義適配器包裝了ViewPager。 當用戶拍照時,我會將圖片加載到viewPager中,以便用戶可以在整個圖片中滑動(例如Google Camera應用)。 我想將已拍攝的圖片(ImageView中的位圖)替換為已過濾的圖片(如Instagram)。
如何在ViewPager中替換/交換兩個ImageView? 我知道這是一個虛擬的問題,但是我找到了幾個解決方案,但沒有一個在起作用。
使用: ImageView imageView1= ((ImageView) viewPager.findViewById (R.id.imageView1));
要獲得更多的圖像處理效果/濾鏡,您可以進行以下操作:
Catalano Framework,它在桌面系統中可作為Android使用。
http://code.google.com/p/catalano-framework/
例:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.