'convert'에 해당되는 글 3건

  1. 2013.01.23 [Android] convert intent to bitmap
  2. 2013.01.21 [Android] Convert bitmap to file
  3. 2013.01.21 [Android] convert drawable to bitmap

송신
Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);


수신
if(getIntent().hasExtra("byteArray")) {
    ImageView previewThumbnail = new ImageView(this);
    Bitmap b = BitmapFactory.decodeByteArray(
        getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArr
ay").length);       
    previewThumbnail.setImageBitmap(b);
}

 

 

Reference: http://blog.naver.com/zighart8456/159472785

 

 

 

 

Posted by Jyui

//assume that variable b is Bitmap instance

String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(extStorageDirectory, "er.PNG");
try {
    outStream
= new FileOutputStream(file);
    b
.compress(Bitmap.CompressFormat.PNG, 100, outStream);
    outStream
.flush();
    outStream
.close();
}
catch(Exception e)
{}

 

 

 

Reference : http://stackoverflow.com/questions/649154/android-bitmap-save-to-location

 

 

 

 

 

Posted by Jyui

FROM drawable TO bitmap :

Drawable d = ImagesArrayList.get(0); 
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

 

FROM resource id of drawable TO bitmap:

Bitmap b1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource);

 

Reference:

http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap

 

 

 

 

Posted by Jyui