public class AndroidCamera extends Activity implements SurfaceHolder.Callback{
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;;
PictureCallback rawCallback;
ShutterCallback shutterCallback;
PictureCallback jpegCallback;
private Bitmap bitmap;
TextView colorRGB;
Config config;
String callname;
String callnameRimage;
EditText txtData, PatientInfo,PatientAge;
ImageView imageView = null;
ImageView imageView2 = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonStartCameraPreview = (Button)findViewById(R.id.startcamerapreview);
Button buttonStopCameraPreview = (Button)findViewById(R.id.stopcamerapreview);
Button buttonCapturePreview = (Button) findViewById(R.id.capturepreview);
Button testButton = (Button) findViewById(R.id.testButton);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
rawCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Log.d("Log", "onPictureTaken - raw");
}
};
shutterCallback = new ShutterCallback()
{
public void onShutter() {
Log.i("Log", "onShutter'd");
}
};
jpegCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Image");
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
name = s.toString() + ".jpg";
File output = new File(imagesFolder, name);
callname = "/sdcard/Asw/Raw Image/" + name;
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{}
Log.d("Log", "onPictureTaken - jpeg");
buttonStartCameraPreview.setOnClickListener(new Button.OnClickListener()
{
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onClick(View v)
{
if(!previewing)
{
camera = Camera.open(0);
if (camera != null)
{
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
}
catch (IOException e)
{
e.printStackTrace();
}
}else txtData.setText("null");
}
}});
buttonCapturePreview.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
captureImage();
}
});
buttonStopCameraPreview.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
if(camera != null && previewing)
{
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
}});
}
private void captureImage()
{
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
private void displayimages()
{
setContentView(R.layout.display);
callnameRimage = "/sdcard/Asw/Raw Image/" + name;
Bitmap bitmap1 = BitmapFactory.decodeFile(callnameRimage);
imageView2=(ImageView)findViewById(R.id.imageView2);
imageView2.setImageBitmap(bitmap1);
Button backButton = (Button) findViewById(R.id.back);
backButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
Intent intent = new Intent(AndroidCamera.this, AndroidCamera.class);
startActivity(intent);
}
});
}
}
我想查看上一张图片,然后点按一下按钮。图像存储在文件夹中。该文件夹将包含许多图像,这些图像以日期和时间作为图像名称存储。我希望通过比较其日期和时间来获取上一张图片。任何人都可以建议我更轻松地做到这一点
答案 0 :(得分:0)
获取文件名,格式化它们然后您可以将日期与以下内容进行比较:
date1.compareTo(date2);
相等时返回0.
当date1更早时返回低于0的值。
当date2更早时返回高于0的值。