Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void setImage(){
- if (loadPicture("hello", bitmap) != null) {
- Toast.makeText(this, "not null", Toast.LENGTH_SHORT).show();
- imageView.setImageBitmap(loadPicture("hello", bitmap));
- }
- }
- private void takePicture(){
- Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
- File photo =
- new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
- intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
- imageUri = Uri.fromFile(photo);
- startActivityForResult(intent, 0);
- }
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- Uri selectedImage = imageUri;
- getContentResolver().notifyChange(selectedImage, null);
- ContentResolver cr = getContentResolver();
- try {
- bitmap = android.provider.MediaStore.Images.Media
- .getBitmap(cr, selectedImage);
- imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, bitmap.getHeight()/2, bitmap.getWidth()/2, false));
- //**Where I save the picture**
- savePicture("hello", bitmap, getApplicationContext());
- }
- private void savePicture(String filename, Bitmap b, Context ctx){
- try {
- ObjectOutputStream oos;
- FileOutputStream out;// = new FileOutputStream(filename);
- out = ctx.openFileOutput(filename, Context.MODE_PRIVATE);
- oos = new ObjectOutputStream(out);
- b.compress(Bitmap.CompressFormat.PNG, 100, oos);
- oos.close();
- oos.notifyAll();
- out.notifyAll();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private Bitmap loadPicture(String filename, Bitmap b){
- // Drawable myImage = null;
- try {
- FileInputStream fis = openFileInput(filename);
- ObjectInputStream ois = null;
- try {
- ois = new ObjectInputStream(fis);
- } catch (StreamCorruptedException e1) {
- e1.printStackTrace();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- // myImage = Drawable.createFromStream(ois, filename);
- b = BitmapFactory.decodeStream(ois);
- try {
- ois.close();
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- // return myImage;
- return b;
- }
- out = ctx.openFileOutput(filename, Context.MODE_PRIVATE);
- out = ctx.openFileOutput(filename, Context.MODE_WORLD_READABLE);
Add Comment
Please, Sign In to add comment