0

こんにちはみんな私は問題があります私はEditTextの使用で画像を表示する必要があります:ImageGetter。この作品

String html = "<img src=\"ic_launcher\">";
    CharSequence text = Html.fromHtml(html, new Html.ImageGetter(){
        public Drawable getDrawable(String source){
            int id = getResources().getIdentifier(source, "drawable", getPackageName());
            Drawable d = getResources().getDrawable(id);
            int w = d.getIntrinsicWidth();
            int h = d.getIntrinsicHeight();
            d.setBounds(0, 0, w, h);

            return d;
        }
    }, null);

    mContentEditText.setText(text);

しかし、「R.drawable.IMAGE_NAME」ではなく、SDカードの画像が必要です。ありがとう

4

3 に答える 3

0
String html2 = "<img src=\"a.jpg\">";
    CharSequence text2 = Html.fromHtml(html2, new Html.ImageGetter(){
        public Drawable getDrawable(String source){
            String path = "/sdcard/a/" + source;
            File f = new File(path);
            Drawable bmp = Drawable.createFromPath(f.getAbsolutePath());
            bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
            return bmp;
        }
    }, null);
    display.setText(text2);

私のために働くです!100%thx all :)

于 2012-12-06T20:36:33.167 に答える
0
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

     mPath ="Your image Path here";
     l1=(LinearLayout) findViewById(R.id.layout1);
     l1.setBackgroundColor(Color.WHITE);
     System.out.println(mPath);

         Bitmap b=Bitmap.createScaledBitmap(BitmapFactory.decodeFile(mPath),l1.getWidth(),l1.getHeight(),false);
if(b!=null){

        ImageView iv=new ImageView(this);
            iv.setImageBitmap(b);
    l2.addView(iv);
    }


}

これが私のために働くコードです.それがあなたを助けることを願っています.

于 2012-12-06T12:00:48.513 に答える
0

外部ストレージから読み取ることができるように、マニフェストに適切なアクセス許可を適用する必要があります。次に、必要な画像を SD カードで検索するコードを作成します。

Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());

imageFile は ImageFile です。たとえば、次のようになります。File imageFile = new File("/sdcard/gallery_photo_4.jpg");

于 2012-12-06T11:55:43.407 に答える