1

私はアンドロイド学習者です。私は画像比較を試みていました。サイズが異なる同じ画像の画像が同じではないことが示されたので、 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();
                    }
            }
4

1 に答える 1