2013-06-20 9 views
6

To jest mój kod. Chcę dodać podpis z obrazem. Proszę pomóż mi.Jak dodać podpis do udziału obrazu na Instagram w systemie Android?

private void shareInstagram(Uri uri){ 

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("image/*"); // set mime type 
    shareIntent.putExtra(Intent.EXTRA_STREAM,uri); // set uri 
    shareIntent.putExtra(Intent.EXTRA_TITLE, "Sample title"); 

    shareIntent.setPackage("com.instagram.android"); 

    startActivity(shareIntent); 
      } 

Odpowiedz

0

powinieneś napisać napis na obrazku, a następnie utworzyć uri.

private Bitmap writeTextOnDrawable(int drawableId, String text) { 

     Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId) 
       .copy(Bitmap.Config.ARGB_8888, true); 

     Typeface tf = Typeface.create("Helvetica", Typeface.BOLD); 

     Paint paint = new Paint(); 
     paint.setStyle(Style.FILL); 
     paint.setColor(Color.WHITE); 
     paint.setTypeface(tf); 
     paint.setTextAlign(Align.CENTER); 
     paint.setTextSize(convertToPixels(mContext, 11)); 

     Rect textRect = new Rect(); 
     paint.getTextBounds(text, 0, text.length(), textRect); 

     Canvas canvas = new Canvas(bm); 

     //If the text is bigger than the canvas , reduce the font size 
     if(textRect.width() >= (canvas.getWidth() - 4))  //the padding on either sides is considered as 4, so as to appropriately fit in the text 
      paint.setTextSize(convertToPixels(mContext, 7));  //Scaling needs to be used for different dpi's 

     //Calculate the positions 
     int xPos = (canvas.getWidth()/2) - 2;  //-2 is for regulating the x position offset 

     //"- ((paint.descent() + paint.ascent())/2)" is the distance from the baseline to the center. 
     int yPos = (int) ((canvas.getHeight()/2) - ((paint.descent() + paint.ascent())/2)) ; 

     canvas.drawText(text, xPos, yPos, paint); 

     BitmapDrawable bmd = new BitmapDrawable(getResources(), bm); 
    Bitmap newbit; 
               newbit=bmd.getBitmap(); 
return newbit; 
    } 
    public static int convertToPixels(Context context, int nDP) 
    { 
     final float conversionScale = context.getResources().getDisplayMetrics().density; 

     return (int) ((nDP * conversionScale) + 0.5f) ; 

    } 

ref: Add text to image in android programmatically


Zapisz bitmapy do pliku:

Save bitmap to file function


utworzyć URI z pliku:

Uri.fromFile(new File(<your image absolute path>)); 

Następnie przechodzą ten URI do funkcji

private void shareInstagram(Uri uri){ 

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("image/*"); // set mime type 
    shareIntent.putExtra(Intent.EXTRA_STREAM,uri); // set uri 
    shareIntent.putExtra(Intent.EXTRA_TITLE, "Sample title"); 

    shareIntent.setPackage("com.instagram.android"); 

    startActivity(shareIntent); 
      } 

nadziei trzeba działać

+0

Kalpesh: Czy to działa, aby dodać podpis? – akshay

+0

Umieszczanie napisów na obrazie jest złym rozwiązaniem. Czy podpis na Instagramie nie jest używany? – Diederik

Powiązane problemy