2016-06-16 7 views
-1

私は画像を持つ2つのビットマップを持っていますが、私はこれらの両方を比較したいが、これはできません。これを行う方法を教えてください/?私は彼がsharedprefrencesに保存壁紙の壁紙を設定し、再びユーザーが再びこの無線LANに接続したときに無線LANに接続する無線LANベースのアプリを持っていますこれは彼がsharedprefrence.now問題に保存しているこれはビットマップを比較して、壁紙がすでに同じ画像を持っているかどうかをチェックします。何もしません。そして、ビットマップが等しくない場合、sharedfrefencesを壁紙に保存します。 ここに私のコードです。 uは壁紙用のファイルを設定し比較2のAndroidの問題Bitmap

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

? – PeDuCKA

+0

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

答えて

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

あなたは私のコードをチェックすることができます私はwallpaperManagerから壁紙を得るファイルがありません – xtylish