那就是如何將圖片送至下一個頁面
網路上的資訊似乎都轉成陣列傳送
但傳送的容量又會受到限制
這似乎已經成為大家都痛
目前的作法僅供參考
A Activity
try {
Bitmap bitmap = drawableToBitmap(imageView.getDrawable());
File file = new File(getCacheDir(),"MyImage");
FileOutputStream fileOutStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutStream);
Intent intent = new Intent();
intent.setClass(MainActivity.this, BActivity.class);
intent.putExtra("image", Uri.fromFile(file) );
startActivity(intent);
catch (FileNotFoundException e) {
e.printStackTrace();
}
public static Bitmap drawableToBitmap(Drawable drawable) {
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
B Activity
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
Uri uri = getIntent().getParcelableExtra("MyImage");
imageView.setImageURI(uri);
目前的作法僅供參考
歡迎轉載,請註明出處