2016-06-16 13 views
-1

Ich habe eine zwei Bitmap, die Bilder haben, die ich beide vergleichen möchte, aber ich kann das nicht tun. Bitte sag mir wie man das macht /? Ich habe eine Wi-Fi-Basis-App, in der Benutzer mit Wifi verbinden, wenn er die Tapete Hintergrundbild speichern in den Shared Prefrences und wieder erhalten, wenn der Benutzer wieder mit diesem Wifi seine Tapete Auto zu diesem Wechsel, die er in sharedprefrence.now Problem haben verbunden ist Dies ist nicht Bitmap zu vergleichen, um zu überprüfen, ob Tapeten bereits das gleiche Bild haben, dann tut es nichts und wenn Bitmap nicht gleich sind, dann legt es das Sharedfreefenses Bild auf Hintergrundbild. Hier ist mein Code.Android-Problem mit 2 Bitmap vergleichen

final Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 

      @Override 
      public void run() { 
// 
       ConnectivityManager connectivityManager = (ConnectivityManager) 
         context.getSystemService(Context.CONNECTIVITY_SERVICE); 
       NetworkInfo mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 

       if (mWifi.isConnected()) { 
         final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 
         final WifiInfo conn = wifiManager.getConnectionInfo(); 
        //Toast.makeText(MainActivity.this, con.getSSID()+"",Toast.LENGTH_LONG).show(); 

        if (conn.getSSID().toString().equalsIgnoreCase("\"" + homewifi + "\"")) { 

         final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 
         final Drawable wal = wallpaperManager.getDrawable(); 
         final Bitmap bitmap = ((BitmapDrawable)wal).getBitmap(); 

         ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
         final byte[][] b = {baos.toByteArray()}; 
         String encodedImage = Base64.encodeToString(b[0], Base64.DEFAULT); 
         // textEncode.setText(encodedImage); 

         SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(context); 
         SharedPreferences.Editor edit=shre.edit(); 
         edit.putString("image_data",encodedImage); 
         edit.commit(); 

         final String previouslyEncodedImage = shre.getString("image_data", ""); 

            b[0] = Base64.decode(previouslyEncodedImage, Base64.DEFAULT); 
            bit = BitmapFactory.decodeByteArray(b[0], 0, b[0].length); 

             if (!bitmap.equals(bit)) { 
              try { 
               context.setWallpaper(bit); 
              } catch (IOException e) { 
               e.printStackTrace(); 
              } 
              Toast.makeText(Profile1Activity.this,"wallpaper set", Toast.LENGTH_SHORT).show(); 
             } else { 
               Toast.makeText(Profile1Activity.this,"wallpaper already set", Toast.LENGTH_LONG).show(); 
             }  
        } 
       } 
        else { 

        } 

       handler.postDelayed(this, 5000); 
      } 
     }, 5000); 

    } 
+0

wo u-Datei für den Hintergrund gesetzt? – PeDuCKA

+0

if (! Bitmap.equals (bit)) { try { context.setWallpaper (Bit); } catch (IOException e) { e.printStackTrace(); } – xtylish

Antwort

0
private static String mergeTwoImg(String botImgPath, String topImgPath, float leftPadding, float topPadding) { 
     Bitmap bottomImage = BitmapFactory.decodeFile(botImgPath); 
     Bitmap topImage = BitmapFactory.decodeFile(topImgPath); 

     Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types 
     Bitmap bmp = Bitmap.createBitmap(bottomImage.getWidth(), bottomImage.getHeight(), conf); // this creates a MUTABLE bitmap 

     Canvas comboImage = new Canvas(bmp); 

     comboImage.drawBitmap(bottomImage, 0f, 0f, null); 
     comboImage.drawBitmap(topImage, leftPadding, topPadding, null); 

     File file = new File(outPath + "/mergingImg.png"); 
     if (file.exists()) { 
      file.delete(); 
     } 

     OutputStream os = null; 
     try { 
      os = new FileOutputStream(outPath + "/mergingImg.png"); 
      bmp.compress(Bitmap.CompressFormat.PNG, 50, os); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return outPath + "/mergingImg.png"; 
    } 
+0

Sie können meinen Code überprüfen Ich habe keine Datei Ich bekomme Hintergrundbilder von WallpaperManager – xtylish