how to read image uri in to byte conversion in android image upload in sdcard
- by satyamurthy
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1 = (Button) findViewById(R.id.Button01);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
startActivityForResult(new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
}
});
}
public void onActivityResult(int requestCode,int resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
Uri selectedImage = data.getData();
Cursor cur = PhotoImage.this.managedQuery(selectedImage, null, null, null, null);
if(cur.moveToFirst())
{
File Img = new File(selectedImage+inFileType);
try {
FileInputStream fis = new FileInputStream(Img);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data1 = baos.toByteArray();
for (int i = 0; i < data1.length; i++)
{
System.out.print(""+data1[i]);
}
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
this code not i am implementing file not found error please help some suggition