gpt4 book ai didi

java - 如何将捕获的图像路径从imageview保存到mysql数据库

转载 作者:行者123 更新时间:2023-11-29 22:31:26 25 4
gpt4 key购买 nike

我想知道是否有人可以帮助我,我正在 Android 上创建表单,并且用户必须插入图像。应用程序打开相机,用户可以拍照并将该图像设置为 ImageView 。我的问题是如何获取 imageview 的图像路径以使用 php 将其保存到 mysql 数据库。

private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}



@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

// save file url in bundle as it will be null on screen orientation
// changes
outState.putParcelable("file_uri", fileUri);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);

// get the file url
fileUri = savedInstanceState.getParcelable("file_uri");
}




@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {


filePath = getPath(fileUri);

final Bitmap image = BitmapFactory.decodeFile(filePath);

image1.setImageBitmap(image);

} else if (resultCode == RESULT_CANCELED) {

// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"No picture for your Schedule", Toast.LENGTH_SHORT)
.show();

} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}

}
}

最佳答案

嗯,我想你已经拥有了你需要的东西。当您使用时:

filePath = getPath(fileUri);

这里有 Uri 和路径。现在有了这些信息,您应该在服务器中的 savePath.php 文件中创建一个 HttpPost。您必须在 AsyncTask 内发出请求。

http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient

关于java - 如何将捕获的图像路径从imageview保存到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29745489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com