2012-06-18 5 views
0

안드로이드에 새로운 메신저 그리고 나는 안드로이드에 사진을 표시하는 방법을 알아 내려고 노력했습니다. 나는 운없이 일주일 내내 검색 및 이미지 갤러리갤러리에서 android app wallpaper

에서 앱의 배경 화면을 설정하는 방법에 대한 안드로이드 샘플 코드 또는 예제이 있는지 알고 싶어했습니다 모든

+0

[1]은 (는) 당신이 참조 할 수있는 다소 관련된 질문입니다. [1] : http://stackoverflow.com/questions/3035050/setting-wallpaper-through-code –

답변

0

사용 :

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    switch (requestCode) { 
    case PICK_IMAGE: 

     if (resultCode == Activity.RESULT_OK) { 
      Uri selectedImageUri = data.getData(); 
      try { 
       // OI FILE Manager 
       String filemanagerstring = selectedImageUri.getPath(); 

       // MEDIA GALLERY 
       String selectedImagePath = getPath(selectedImageUri); 

       if (selectedImagePath != null) { 
        filePath = selectedImagePath; 
       } else if (filemanagerstring != null) { 
        filePath = filemanagerstring; 
       } else { 
        Toast.makeText(getApplicationContext(), "Unknown path", 
          Toast.LENGTH_LONG).show(); 

       } 

       if (filePath != null) {   

        decodeFile(filePath); 
       } else { 
        bitmap = null; 
       } 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(), "Internal 
        error",Toast.LENGTH_LONG).show(); 

      } 
     } 
     break; 
    default: 
    } 



} 


    //Decode file() where you will get decoded file and then you can use that image 
     //file according to your requirement 

    public void decodeFile(String filePath) { 

    // Decode image size 
    BitmapFactory.Options o = new BitmapFactory.Options(); 
    o.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(filePath, o); 

    // The new size we want to scale to 
    final int REQUIRED_SIZE = 1024; 

    // Find the correct scale value. It should be the power of 2. 
    int width_tmp = o.outWidth, height_tmp = o.outHeight; 
    int scale = 1; 
    while (true) { 
     if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) 
      break; 
     width_tmp /= 2; 
     height_tmp /= 2; 
     scale *= 2; 
    } 

    // Decode with inSampleSize 
    BitmapFactory.Options o2 = new BitmapFactory.Options(); 
    o2.inSampleSize = scale; 
    bitmap = BitmapFactory.decodeFile(filePath, o2); 

    image.setImageBitmap(bitmap);// set ImageView in your case set Layout 
       //background 

} 
-1

확인하시기 바랍니다 감사합니다 코드.

Bitmap mBitmap = BitmapFactory.decodeResource("imageID"); 

       WallpaperManager myWallpaperManager = WallpaperManager 
         .getInstance(getApplicationContext()); 

       try { 
        myWallpaperManager.setBitmap(mBitmap); // here your image bitmap. 
        Toast.makeText(SetWallPaper.this, "Wallpaper set", 
          Toast.LENGTH_SHORT).show(); 
       } catch (IOException e) { 
        Toast.makeText(SetWallPaper.this, 
          "Error setting wallpaper", Toast.LENGTH_SHORT) 
          .show(); 
       } 

내가 도움이된다고 생각합니다. 이미지 GALLARY

//Declare private static final int PICK_IMAGE = 1; 

    try { 
       Intent intent = new Intent(); 
       intent.setType("image/*"); 
       intent.setAction(Intent.ACTION_GET_CONTENT); 
       startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show(); 
       Log.e(e.getClass().getName(), e.getMessage(), e); 
      } 

에서 그리고 활동 결과 쓰기에서 이미지를 선택하는 방법을 다음

0

안드로이드 개발 튜토리얼에 대한 새로운 보스턴의 웹 사이트를 검색해보십시오, 나는 생각 혀 (41, 42) 갤러리 나 카메라에서 이미지를 얻는 방법을 가르치고 배경 화면으로 설정합니다. 이 링크를 사용해보십시오 http://thenewboston.org/list.php?cat=6. 해피 코딩 :)

관련 문제