我是安卓学习者。我正在尝试图像比较。它显示不同大小的相同图像的图像不同,因此我使用 createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) 重新缩放了图像。即使在重新缩放之后,当我比较我得到的结果时,两个图像都是不同的。请帮帮我。
bmpimg1 = BitmapFactory.decodeFile(path1);
bmpimg2 = BitmapFactory.decodeFile(path2);
int bm1Height = bmpimg1.getHeight();
int bm1Width = bmpimg1.getWidth();
int bm1Res = bm1Height * bm1Width;
int bm2Height = bmpimg2.getHeight();
int bm2Width = bmpimg2.getWidth();
int bm2Res = bm2Height * bm2Width;
if(bm1Res==bm2Res){
Toast.makeText(getApplicationContext(), "Both Images Same Size", Toast.LENGTH_SHORT).show();
if(bmpimg1.sameAs(bmpimg2)){
Toast.makeText(getApplicationContext(), "Same", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Not Same", Toast.LENGTH_LONG).show();
}
}
if (bm1Res > bm2Res)
{
Bitmap rbm1 = Bitmap.createScaledBitmap(bmpimg1, bmpimg2.getWidth(), bmpimg2.getHeight(), true);
ImageView imageView1 = (ImageView) findViewById(R.id.image1);
imageView1.setImageBitmap(rbm1);
Toast.makeText(getApplicationContext(), "Image1 has to be Scaled", Toast.LENGTH_SHORT).show();
if(rbm1.sameAs(bmpimg2)){
Toast.makeText(getApplicationContext(), "Same", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Not Same", Toast.LENGTH_LONG).show();
}
}
if(bm1Res<bm2Res)
{
Bitmap rbm2 = Bitmap.createScaledBitmap(bmpimg2, bmpimg1.getWidth(), bmpimg1.getHeight(), true);
ImageView imageView2 = (ImageView) findViewById(R.id.image2);
imageView2.setImageBitmap(rbm2);
Toast.makeText(getApplicationContext(), "Image2 has to be Scaled", Toast.LENGTH_SHORT).show();
if(bmpimg1.sameAs(rbm2)) {
Toast.makeText(getApplicationContext(), "Same", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Not Same", Toast.LENGTH_LONG).show();
}
}