so I need to have the user take a photo, crop it, then store the cropped image as a URI in my sqllite database. I can get the crop to work, but then I can't figure out how to get the URI for that image... I also would like the full size image to appear in the dynamic ImageView on the page to take the photo, instead of the little thumbnail, but I should be able to do that once I get the URI.
I can retrieve the URI from the database using another class.
So the issue is that the crop works, but then I can use the cropped image. Maybe it would work to overwrite the other image using the cropped image?
Here is my code...
package com.example.blizz_000.lureorganizer;
import android.app.Activity;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class CrankbaitAdder extends Activity implements View.OnClickListener {
static final int REQUEST_IMAGE_CAPTURE = 1;
Button sqlWrite, sqlView;
EditText sqlModel, sqlMaker, sqlSize, sqlColor, sqlDiveDepth;
ImageView sqlPhoto, sqlPhoto2;
String PHOTO_URI;
private Uri picUri;
final int CAMERA_CAPTURE = 1;
//keep track of cropping intent
final int PIC_CROP = 2;
private Uri PHOTO_URIURI;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.crankbaitadder);
//Get Buttons
sqlPhoto = (ImageView) findViewById(R.id.photo);
sqlPhoto2 = (ImageView) findViewById(R.id.photo);
sqlWrite = (Button) findViewById(R.id.bsqlWrite);
sqlModel = (EditText) findViewById(R.id.sqlModel);
sqlMaker = (EditText) findViewById(R.id.sqlMaker);
sqlSize = (EditText) findViewById(R.id.sqlSize);
sqlColor = (EditText) findViewById(R.id.sqlColor);
sqlDiveDepth = (EditText) findViewById(R.id.sqlDiveDepth);
sqlWrite.setOnClickListener(this);
int imageResource = getResources().getIdentifier("@drawable/lure", null, getPackageName());
Drawable res = getResources().getDrawable(imageResource);
sqlPhoto.setImageDrawable(res);
sqlPhoto.setOnClickListener(this);
}
String mCurrentPhotoPath;
static final int REQUEST_TAKE_PHOTO = 1;
private void performCrop(){
//call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 512);
cropIntent.putExtra("outputY", 512);
//retrieve data on return
cropIntent.putExtra("scale", true);
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
if (resultCode == RESULT_OK) {
if(requestCode == CAMERA_CAPTURE){
picUri = data.getData();
//carry out the crop operation
performCrop();
}
else if(requestCode == PIC_CROP){
// PHOTO_URI = data.getData().toString(); ************DOES NOT WORK
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
Bitmap photo = extras.getParcelable("data");
sqlPhoto.setImageBitmap(photo);
}
}}
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.bsqlWrite:
boolean DidItWork = true;
try {
String name = sqlModel.getText().toString();
String maker = sqlMaker.getText().toString();
String color = sqlColor.getText().toString();
String size = sqlSize.getText().toString();
String depth = sqlDiveDepth.getText().toString();
String type = "crankbait";
LureOrganizer entry = new LureOrganizer(CrankbaitAdder.this);
entry.open();
//Where to enter data
entry.createEntryWithPhoto(name, maker, color, size, type, depth, PHOTO_URI);
entry.close();
} catch (Exception e) {
DidItWork = false;
String error = e.toString();
Dialog D = new Dialog(this);
D.setTitle("Dangit!");
TextView tv = new TextView(this);
tv.setText(error);
D.setContentView(tv);
D.show();
} finally {
if (DidItWork) {
Dialog D = new Dialog(this);
D.setTitle("Heck Yeah!");
TextView tv = new TextView(this);
tv.setText("Success!");
D.setContentView(tv);
D.show();
}
}
break;
case R.id.photo:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
// dispatchTakePictureIntent();
break;
}
}
}}
Aucun commentaire:
Enregistrer un commentaire