qq_25824541
qq_25824541
采纳率80%
2017-10-29 08:06 阅读 1.4k

关于安卓Bitmap,怎样写一个缩放图片的方法?

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editnote);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_edit);
setSupportActionBar(toolbar);
EditText editText = (EditText)findViewById(R.id.edit_content);
String imagePath = getIntent().getBundleExtra("neirong").getString(
"nei");
SpannableString ss = new SpannableString(imagePath);
Pattern p=Pattern.compile("/mnt/sdcard/.+?\.\w{3}");
Matcher m=p.matcher(imagePath);
while(m.find()){
Bitmap bm = BitmapFactory.decodeFile(m.group());
Bitmap rbm = resizeImage(bm, 100, 100);
ImageSpan span = new ImageSpan(this, rbm);
ss.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
editText.setText(ss);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    InitView();
}
    对应如上代码,resizeImage方法该怎么写?
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    zgy621101 紫风幻雪 2017-10-30 00:38
    点赞 评论 复制链接分享
  • caozhy 从今以后生命中的每一秒都属于我爱的人 2017-10-29 12:22
    点赞 1 评论 复制链接分享
  • qq_33756493 昵称_Justin 2017-10-30 09:33

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    String fullFilePathString = f.getAbsolutePath();
    WindowManager windowManager = this.getWindowManager();
    Display winDisplay = windowManager.getDefaultDisplay();
    int width = winDisplay.getWidth();
    int scale = 1;
    if (options.outWidth>width) {
    scale = options.outWidth/width;

                }
                options.inJustDecodeBounds = false;
                options.inSampleSize = 3;
                Bitmap myBitmap = BitmapFactory.decodeFile(fullFilePathString,options);
                //myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
                imageView.setImageBitmap(myBitmap);
    
    点赞 评论 复制链接分享

相关推荐