how can read data in image uri in sdcard in byte convertion

Tutorials with advanced 'difficulty' and more Lines of Code.

how can read data in image uri in sdcard in byte convertion

Postby narasimharao » Mon Apr 05, 2010 2:31 pm

hi sir
i am implementing this code i got image uri how can read data in imagepath in sdcard

String inFileType = ".jpg";
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 = Upload.this.managedQuery(selectedImage, null, null, null, null);
if(cur.moveToFirst())
{
try
{ byte[]buffer = null;
System.out.println("1................................");
File Img = new File(selectedImage.getPath()+inFileType);
System.out.println("2............."+Img);
FileInputStream is = null;
try
{
is = new FileInputStream(Img);
is.read(buffer);
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(is);
bis.close();
is.close();
System.out.println("3..........."+is);
} catch (FileNotFoundException e) {
Log.d("John: ", "file Not Found");
}

Bitmap bm;
bm = BitmapFactory.decodeStream(is, null, null);
ImageView pic=(ImageView)this.findViewById(R.id.picview);
pic.setImageBitmap(bm);
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}
}
} this code implementing then error file not found how can resolve this problem i am new in android
narasimharao
Junior Developer
Junior Developer
 
Posts: 11
Joined: Mon Apr 05, 2010 12:40 pm
Location: hyderabad

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests