2013-04-05 2 views
0

인 텐트를 사용하여 이미지를 공유하고 있습니다. 다른 곳에서와 같이 stackoverflow에 설명되어 있습니다. 다음은이 사이트에서 훔친 코드 (감사) :)입니다정상적인 이미지 인 것처럼 레이어 목록에 드로어 블을 사용하십시오.

private void share(String nameApp, String imagePath) { 
    List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
    Intent share = new Intent(android.content.Intent.ACTION_SEND); 
    share.setType("image/jpeg"); 
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0); 
    if (!resInfo.isEmpty()){ 
     for (ResolveInfo info : resInfo) { 
      Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND); 
      targetedShare.setType("image/jpeg"); // put here your mime type 

      if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || 
        info.activityInfo.name.toLowerCase().contains(nameApp)) { 
       targetedShare.putExtra(Intent.EXTRA_TEXT,  "My body of post/email"); 
       targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); 
       targetedShare.setPackage(info.activityInfo.packageName); 
       targetedShareIntents.add(targetedShare); 
      } 
     } 

     Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), getResources().getString(R.string.share_select)); 
     chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); 
     startActivity(chooserIntent); 
    } 
} 

내 문제는 내가 공유 할 수있는 JPG이없는,하지만이 같은 드로어 블 및 레이어 목록으로 이미지를 만들 수 있다는 것입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/background01" /> 
    <item android:drawable="@drawable/img02" /> 
    <item android:drawable="@drawable/img07" /> 
</layer-list> 

나는 그들이 전체 이미지를했다 이러한 드로어 블을 사용하고 주() 함수 내에서 사용할 수 있습니다 경우 어떻게 이해하지 않습니다. 어떤 사람이 설명해 주실 수 있습니까?

미리 감사드립니다. 두 개의 오버레이 비트 맵 이미지로 비트 맵을 얼마나

+0

단순히 'R.drawable' id를 통신하여? –

+0

하지만 그건 jpg가 아니며 함수에 경로가 필요합니다. 어떻게 그 드로잉 ID로 생성 할 수 있습니까? –

+0

오, 죄송합니다. 내 잘못입니다. 이메일을 보내시겠습니까? 그런 다음 XML 드로어 블을 주어진 크기의 Canvas로 렌더링하고 저장하고 전달해야합니다. –

답변

1

그게 전부 :

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { 
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); 
    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp1, new Matrix(), null); 
    canvas.drawBitmap(bmp2, new Matrix(), null); 
    return bmOverlay; 
} 

당신은 당신이 어디를 저장하고 방법을 통해 공유 할 수 있습니다 비트 맵을 일단

.

+0

감사합니다. 이것은 내 문제를 해결할 수 있지만, 내가 가지고있는 하나의 다른 XML에 대한 코드를 작성해야하는 즉시 많은 작업을 생성한다. 아시다시피 비트 맵을 drawable.xml에서 렌더링하는 대신 다른 비트 맵에서 직접 렌더링하는 방법이 있습니까? 오버레이 (int resId) 함수와 같은 것? –

+1

과 같은 리소스 ID에서 비트 맵을 직접 가져올 수 있는지 확인하십시오. Bitmap mp = BitmapFactory.decodeResource (getResources(), R.drawable.image); 그래서 메서드 호출은 오버레이 (mp, mp1)처럼됩니다. –

+0

나는이 솔루션을 섞을 것이다 : http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap 나는 오버레이를 만들기 위해 어쨌든 필요하지 않다. 내가 포함 된 공유 기능과 비트 맵을 통합 할 수 있습니다. –

관련 문제