Need some guidelines using Camera, Thumbails and Gallery

All your problems with Audio, Video and Images.

Need some guidelines using Camera, Thumbails and Gallery

Postby mateo » Tue Jan 04, 2011 5:29 am

Hello, I'm currently developing an app. One part of it takes pictures, store them on the sdcard and saves its path into a database.

Now my problems are:

    The pictures are saved twice. Once in the gallery, another in the specified folder. Is there any way to prevent this? I want the pictures taken within the app to stay within the app (What happens in Vegas stays in Vegas :twisted: )

    My second issue is that i want to create a thumbail from each picture taken so to create a gallery of this pictures. I know I can create an Intent to make a picture or a thumbail, but I want to get both, is there any easy way to do this? Maybe i can create the Intent to call the camera and do a .putExtra to make it come with a thumbail as well?

    My third issue is actually a doubt. I know i can ask the gallery to display a picture/s. But that's not enough. What I actually want to do is to display only the pictures taken from my app, in an specified order(that can be modified from the preferences) according to a query from my database . Is it possible to make the gallery work like this or should I create my own gallery view for this purpose?


This is what I'm doing now for this purpose. I chopped it down a little, removed some stuff of the Layout cause firstly it was meant to display thumbails, that i have not created yet, and also i have not tackle it to be displayed on a dinamic RelativeLayout yet.

How it is showed now it only displays a button that when pressed goes to the cam and specifies where to save the pic. If the pic is taken then the path along an id that comes from a previous class its stored on my database.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class PicturesL extends Activity implements OnClickListener {
  2.  
  3.        
  4.     private ArrayList<File> imageFiles = new ArrayList<File>();
  5.     private ArrayList<Bitmap> imageBitm = new ArrayList<Bitmap>();
  6.     private ArrayList<ImageView> imageView = new ArrayList<ImageView>();
  7.     private static int TAKE_PICTURE = 1;
  8.     private Uri outputFileUri;
  9.     private String PATH;
  10.     private StringBuilder PicsDate = new StringBuilder();
  11.     private GregorianCalendar calendar = new GregorianCalendar();
  12.     private CaWaApplication application;
  13.     private long ListID;
  14.    
  15.         @Override
  16.         public void onCreate(Bundle savedInstancedState) {
  17.                 super.onCreate(savedInstancedState);
  18.                 RelativeLayout layout = new RelativeLayout(this);
  19.                 Button TakePic = new Button(this);
  20.                 TakePic.setText("Take Picture");
  21.                 TakePic.setId(67);
  22.                 TakePic.setOnClickListener(this);
  23.                 application = (CaWaApplication) getApplication();
  24.                 ListID = getIntent().getExtras().getLong("listid");
  25.                
  26.                 Log.d("PicturesL", "ListID: " + ListID);
  27.                
  28.                
  29.                
  30.                
  31.                 }
  32.                 RelativeLayout.LayoutParams Takelp = new RelativeLayout.LayoutParams(RelativeLayout.
  33.                                 LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  34.                 Takelp.addRule(RelativeLayout.CENTER_HORIZONTAL);
  35.                 Takelp.addRule(RelativeLayout.BELOW);
  36.                
  37.                 layout.addView(TakePic, Takelp);
  38.                 setContentView(layout);
  39.         }
  40.  
  41.         @Override
  42.         public void onClick(View v) {
  43.                 switch(v.getId()) {
  44.                 case 67:
  45.                        
  46.                         saveFullImage();
  47.                         break;
  48.                 }
  49.                
  50.         }
  51.        
  52.     private void saveFullImage() {
  53.        
  54.        
  55.         Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  56.         Date time = new Date();
  57.         calendar.setTime(time);
  58.        
  59.         PicsDate.append(calendar.get(calendar.YEAR) + "-");
  60.         PicsDate.append(calendar.get(calendar.MONTH) + "-");
  61.         PicsDate.append(calendar.get(calendar.DAY_OF_MONTH) + "-");
  62.         PicsDate.append(calendar.get(calendar.HOUR)+ "-");
  63.         PicsDate.append(calendar.get(calendar.MINUTE)+ "-");   
  64.         PicsDate.append(calendar.get(calendar.SECOND));
  65.         PicsDate.append(".jpg");
  66.         String myPicName = PicsDate.toString();
  67.        
  68.         Log.d("PicturesL", "PicsDate: " + PicsDate.toString());
  69.         PicsDate.delete(0, PicsDate.length());
  70.        
  71.         File file = new File(Environment.getExternalStorageDirectory(),
  72.         myPicName);
  73.         outputFileUri = Uri.fromFile(file);
  74.         PATH = outputFileUri.toString();
  75.         PATH = PATH.substring(11);
  76.         intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
  77.        
  78.         Log.d("PicturesL", "outputfileuri " + outputFileUri + " MediaStore " + MediaStore.EXTRA_OUTPUT + " PATH " + PATH );
  79.        
  80.         startActivityForResult(intent, TAKE_PICTURE);
  81.      }
  82.     //Store vars when taking picture
  83.     @Override
  84.     public void onSaveInstanceState(Bundle savedInstancedState) {
  85.         savedInstancedState.putString("PATH", PATH);
  86.         savedInstancedState.putLong("ListID", ListID);
  87.         super.onSaveInstanceState(savedInstancedState);
  88.     }
  89.    
  90.     @Override
  91.     public void onRestoreInstanceState(Bundle savedInstancedState) {
  92.         super.onRestoreInstanceState(savedInstancedState);
  93.         ListID = savedInstancedState.getLong("ListID");
  94.         PATH = savedInstancedState.getString("PATH");
  95.     }
  96.    
  97.     //After pic is taken
  98.     @Override
  99.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  100.         super.onActivityResult(requestCode, resultCode, data);
  101.        
  102.         if (requestCode == TAKE_PICTURE) {
  103.                 Uri imageUri = null;
  104.                
  105.                 if      (data != null) {
  106.                         if (data.hasExtra("data")){
  107.                                 // thumbail
  108.                                 Bitmap thumbail = data.getParcelableExtra("data");
  109.                         }
  110.                 }else {
  111.                         //full pic
  112.                        
  113.                         Log.d("PicturesL", "PATH " + PATH );
  114.                         // si saco la foto
  115.                         if (resultCode == -1) {
  116.                                 ModelPics picture = new ModelPics(ListID);
  117.                                
  118.                                  picture.path =  PATH;
  119.                                  
  120.                                  
  121.                                  Toast.makeText(this, "PICTURE TAKEN " + resultCode + " Picture PATH: " + picture.path, Toast.LENGTH_LONG).show();
  122.                                  
  123.  
  124.                                  application.dataManager.insertPicture(picture);
  125.                                  
  126.                        
  127.                         }
  128.                 }
  129.         }
  130.     }
  131.        
  132. }
  133.  
  134.  
  135.  
Parsed in 0.048 seconds, using GeSHi 1.0.8.4



So if anyone is willing to give me some tips / guidance / relevant examples / opinion / etc on the subject please feel free to do so. Anything is more than welcomed. I will be digging myself into this issues, but after a few hours of googling I've decided to create this post, maybe after a few more hours tomorrow i find the answers to my issues, but maybe someone here already knows them and is willing to make my life a little easier. If that is the case:

Thanks!!!


Mateo
mateo
Freshman
Freshman
 
Posts: 6
Joined: Mon Oct 04, 2010 6:58 pm

Top

Re: Need some guidelines using Camera, Thumbails and Gallery

Postby mateo » Wed Jan 05, 2011 12:27 am

Well I've managed to create the thumbnails by opening the saved image into a bitmap, resizing it and saving it into another file. I don't think it is the best way, specially if you can ask the camera to return both, the full size image and the thumbnails. But it does what it is needed.

So one question less
mateo
Freshman
Freshman
 
Posts: 6
Joined: Mon Oct 04, 2010 6:58 pm

Re: Need some guidelines using Camera, Thumbails and Gallery

Postby mateo » Thu Jan 06, 2011 12:41 am

Ok so I've used the Gallery with an ImageAdapter in two separate activities, one displays the thumbnails, and the other the full images.

Using this gallery instead of the default android gallery to display pictures made it really easy to just show the pictures I want in the order I want. But there are certain things i want to do that I don't know if they are possible:

/* I know there are too many questions, if any of them seems to be stupid/obvious please forgive me, my head is not working right after 12 continuous hours of coding, even if none gets answered this post helps me to get my ideas straight of the stuff i need to work on to, but I'm hoping that some of them do though */

1) Can I implement some sort of pinch zoom in the Gallery? (Gallery g;) Or opengl is needed for this sort of effects?

2) Whenever my screen orientation changes I get an fc saying that the image size exceed the vm budget. Is there any way to avoid this or will i have to make the orientation fixed?

3) On my full sized pictures gallery, I have set the images to take over the whole view. The thing is that the images get distorted to fit the screen. Is there any way to force the images to keep scale while taking up the whole view? Or do i have to develop some sort of algorithm to crop the pictures to adjust to the screen size according to the device's screen size?

4) I have not found as well a way to set the picture's orientation. Any clues?

5) Is there any way to make my preview gallery look like an iphone app drawer? (rounded pictures, and some transparent space in between them) Or to something that looks more aerodinamic than a rectangle with its images sticked one next to the other

6) My first question of my first post is still up(I'm getting my pictures saved twice, in my pictures folder and another one in my specified path; from what I've read from the book Professional android development 2(i think), in theory it should only be saving them in the specified path, in practice it doesn't), I need this feature for my app and you guys wouldn't believe the amount of irrelevant stuff I stumbled trying to solve this one.


Well that's it, probably latter i will continue to dig into this issues, I'll try to keep updated my doubts in case anyone takes the time to answer them
mateo
Freshman
Freshman
 
Posts: 6
Joined: Mon Oct 04, 2010 6:58 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests