私はアンドロイド開発者です.私はカメラから写真を撮ろうとする助けが必要でした.写真を取得し、ギャラリービューを追加する方法.どのように可能ですか? 以下の私のコード!!enter code here
ありがとう!!
send_zoo_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String base64string = "";
// bitmap = i.getDrawingCache();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
ImageByte = stream.toByteArray();
base64string = Base64.encodeBytes(ImageByte);
db.execSQL("insert into newanimal(path,selece_animal) values('"
+ base64string + "','" + id + "' )");
Toast.makeText(ThirdActivity.this, "Data inserted", 1).show();
Intent intent = new Intent().setClass(ThirdActivity.this,
ZoobuzzActivity.class);
startActivity(intent);
}
});
}
以下の onactivity 結果メソッド
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("CheckStartActivity", "onActivityResult and resultCode = "
+ requestCode);
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY || requestCode == CAMERA) {
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA) {
Log.d("log", " request code camera " + requestCode);
final File file = getTempFile(this);
try {
selImagePath = file.getAbsolutePath();
Log.v("anim", "path " + selImagePath);
m_bmOCRBitmap = Media.getBitmap(getContentResolver(),
Uri.fromFile(file));
int calwidth;
int calheight;
// OI FILE Manager
FileOutputStream out;
out = new FileOutputStream(file);
int width = m_bmOCRBitmap.getWidth();
int height = m_bmOCRBitmap.getHeight();
if (width > height) {
calwidth = (int) ((width * 250) / height);
calheight = 250;
} else {
calheight = (int) ((height * 200) / width);
calwidth = 200;
}
bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap,
calwidth, calheight, true);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
Log.v("bitmap", " bitmap :" + bitmap);
img_pht.setImageBitmap(bitmap);
hideMenu();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else if (requestCode == GALLERY) {
Uri selectedImageUri = data.getData();
Log.v("", " result code : " + resultCode + " request "
+ requestCode + " data " + data);
realpath = getPath(selectedImageUri);
Log.v("anim", " realpath : " + realpath);
file = new File(realpath);
Log.v("anim", " file : " + file);
m_bmOCRBitmap = BitmapFactory.decodeFile(realpath);
int calwidth;
int calheight;
// OI FILE Manager
FileOutputStream out;
try {
out = new FileOutputStream(file);
int width = m_bmOCRBitmap.getWidth();
int height = m_bmOCRBitmap.getHeight();
if (width > height) {
calwidth = (int) ((width * 250) / height);
calheight = 250;
} else {
calheight = (int) ((height * 200) / width);
calwidth = 200;
}
bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap,
calwidth, calheight, true);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
Log.v("bitmap", " bitmap :" + bitmap);
img_pht.setImageBitmap(bitmap);
hideMenu();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
if (resultCode == 1) {
Log.d("log", " request code di= " + requestCode);
id = data.getExtras().getInt("id");
if (GViewAdapter.imageIDs.get(id).equals("R.drawable")) {
int as = Integer.parseInt("" + GViewAdapter.imageIDs.get(id));
img_chose.setImageResource(as);
} else {
}
Log.v("log", " id" + data.getExtras().getInt("id"));
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
private File getTempFile(Context context) {
final File path = new File(Environment.getExternalStorageDirectory(),
context.getPackageName());
if (!path.exists()) {
path.mkdir();
}
return new File(path, fileName);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (!(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT)
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
public void onBackPressed() {
if (isMenuVisible) {
hideMenu();
} else {
finish();
}
}
エラー
05-02 11:26:35.900: ERROR/AndroidRuntime(510): FATAL EXCEPTION: main
05-02 11:26:35.900: ERROR/AndroidRuntime(510): java.lang.ArrayIndexOutOfBoundsException
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.zoobuzz.FirstActivity$1.onItemClick(FirstActivity.java:39)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.widget.Gallery.onSingleTapUp(Gallery.java:864)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:557)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.widget.Gallery.onTouchEvent(Gallery.java:839)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.View.dispatchTouchEvent(View.java:3766)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.os.Looper.loop(Looper.java:123)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at java.lang.reflect.Method.invoke(Method.java:521)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-02 11:26:35.900: ERROR/AndroidRuntime(510): at dalvik.system.NativeStart.main(Native Method)
enter code here