关于安卓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个回答

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);
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐