File Outputimage;
Private ImageView IV;
public static final int take_photo = 1;
public static final int crop_photo = 2;
Private Uri Imageuri;
Private String Path = Environment.getexternalstoragedirectory ()
. GetAbsolutePath ();
Private String ImagePath;
Private GridView Gv_photos;
String Photopath = path + "/six/image/";
file[] images;
ImageButton image;
List<drawable> lists;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (R.layout.activity_image);
Init ();
}
private void init () {
TODO auto-generated Method Stub
IV = (ImageView) Findviewbyid (r.id.iv_picture);
File F = new file (Photopath);
Images = F.listfiles ();
try {
Lists = new arraylist<drawable> ();
for (int i = 0; i < images.length; i++) {
FileInputStream fil = new FileInputStream (photopath
+ Images[i].getname ());
drawable d = Drawable.createfromstream (fil, NULL);
Lists.add (d);
}
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Gv_photos = (GridView) Findviewbyid (R.id.gv_photos);
Gv_photos.setadapter (New Baseadapter () {
@Override
Public View GetView (int position, View Convertview, ViewGroup parent) {
TODO auto-generated Method Stub
Convertview = View.inflate (Imageactivity.this,
R.layout.item_photo, NULL);
ImageView IV = (ImageView) convertview
. Findviewbyid (R.id.iv_photo_item);
TextView TV = (TextView) convertview
. Findviewbyid (R.id.tv_photo);
Tv.settext (Images[position].getname ());
Iv.setimagedrawable (Lists.get (position));
return convertview;
}
@Override
public long getitemid (int position) {
TODO auto-generated Method Stub
return 0;
}
@Override
Public Object getItem (int position) {
TODO auto-generated Method Stub
return null;
}
@Override
public int GetCount () {
TODO auto-generated Method Stub
return Lists.size ();
}
});
}
public void Selectimage (view view) {
Create a file path for storing pictures after taking pictures
File FilePath = Environment.getexternalstoragedirectory ();
Create this Folder
File Filefolder = new file (Photopath);
if (!filefolder.exists () &&!filefolder.isdirectory ()) {
Filefolder.mkdirs ();
}
The file name cannot always be the same name, so here, you can choose to use the time to do the picture name
SimpleDateFormat formatter = new SimpleDateFormat ("Yyyymmddhhmmss");
Date curdate = new Date (System.currenttimemillis ());//Get current time
String name = "Six" + Formatter.format (curdate);
Create this file
Outputimage = new File (filefolder, name + ". jpg");
Get its name in the display with
ImagePath = photopath + name + ". jpg";
Find Address and call
Imageuri = Uri.fromfile (outputimage);
Intent Intent = new Intent ("Android.media.action.IMAGE_CAPTURE");
Intent.putextra (Mediastore.extra_output, Imageuri);
Start the camera program
Startactivityforresult (Intent, Take_photo);
}
Note that here is to rewrite this method, which must be rewritten!!
@Override
public void Onactivityresult (int requestcode, int resultcode, Intent data) {
Switch (requestcode) {
Case Take_photo:
if (ResultCode = = RESULT_OK) {
Intent Intent = new Intent ("Com.android.camera.action.CROP");
Intent.setdataandtype (Imageuri, "image/*");
Intent.putextra ("scale", true);
Intent.putextra (Mediastore.extra_output, Imageuri);
Start the clipping program
Startactivityforresult (Intent, Crop_photo);
}
Break
Case Crop_photo:
if (ResultCode = = RESULT_OK) {
try {
Bitmap Bitmap = bitmapfactory
. Decodestream (Getcontentresolver (). Openinputstream (
Imageuri));
Show the cropped photo
Iv.setimagebitmap (bitmap);
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
Break
Default
Break
}
}
public void Phototoimage (view view) {
Toast.maketext (Imageactivity.this, "not to be continued ha ~", 0). Show ();
}
Android camera call and storage detailed