画像暗号化アプリに取り組んでいるので、Androidで2つの画像をXORしたいSDカードから画像を取り込み、画像ビューにロードする2つの画像をロードしたので、両方をXORしたい
質問する
3909 次
2 に答える
3
もう 1 つの方法は、Canvas
両方のビットマップに描画することです。1 つのビットマップでは設定が指定されていませんが、もう 1 つのビットマップではオブジェクトPorterDuffXfermode
に toを指定する必要があります。Mode.XOR
Paint
元:
ImageView compositeImageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap1=BitmapFactory.decodeResource(getResources(), R.drawable.batman_ad);
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(), R.drawable.logo);
Bitmap resultingImage=Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig());
Canvas canvas = new Canvas(resultingImage);
// Drawing first image on Canvas
Paint paint = new Paint();
canvas.drawBitmap(bitmap1, 0, 0, paint);
// Drawing second image on the Canvas, with Xfermode set to XOR
paint.setXfermode(new PorterDuffXfermode(Mode.XOR));
canvas.drawBitmap(bitmap2, 0, 0, paint);
compositeImageView.setImageBitmap(resultingImage);
于 2012-08-02T12:23:11.070 に答える
1
xorしたいもの、ピクセルまたはデータ自体によって異なります。とにかく簡単な方法は、画像をすべてのピクセルの配列に変換し、それらを XOR してからビットマップに戻すことです。この例は、同じ解像度のビットマップに対してのみ機能することに注意してください。
//convert the first bitmap to array of ints
int[] buffer1 = new int[bmp1.getWidth()*bmp1.getHeight()];
bmp1.getPixels(buffer1,0,bmp1.getWidth(),0,0,bmp1.getWidth(),bmp1.getHeight() );
//convert the seconds bitmap to array of ints
int[] buffer2 = new int[bmp2.getWidth()*bmp2.getHeight()];
bmp2.getPixels(buffer2,0,bmp2.getWidth(),0,0,bmp2.getWidth(),bmp2.getHeight() );
//XOR all the elements
for( int i = 0 ; i < bmp1.getWidth()*bmp1.getHeight() ; i++ )
buffer1[i] = buffer1[i] ^ buffer2[i];
//convert it back to a bitmap, you could also create a new bitmap in case you need them
//for some thing else
bmp1.setPixels(buffer1,0,bmp1.getWidth(),0,0,bmp2.getWidth(),bmp2.getHeight() );
参照: http://developer.android.com/reference/android/graphics/Bitmap.html
于 2012-08-01T19:10:36.073 に答える