Bitmap缩放(三)
质量压缩
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imageView = findViewById(R.id.image); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon12); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100,bos);//会出现红线但可以运行 byte[] bytes = bos.toByteArray(); Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); imageView.setImageBitmap(bitmap); } }