Send To Pharmacy
按钮时,我希望能够通过蓝牙将ImageView中存储的照片发送到我的电脑。 这可能吗?由于图像在不断变化,我该怎么做?我查看了一些教程和StackOverflow问题,但它们似乎都已经集中在可绘制文件夹中的图像上。
但是在这种情况下,每次用户拍摄照片时,图像都会有所不同。我只想知道如何发送ImageView中的当前照片,然后通过蓝牙将其发送到PC。感谢您的帮助,我对此表示赞赏。
package com.cognizant.expressprescriptionregistration;
import static android.os.Environment.getExternalStoragePublicDirectory;
public class Register extends AppCompatActivity {
Button bPicButton;
ImageView imageView;
String pathToFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
bPicButton = findViewById(R.id.bTakePhoto);
imageView = findViewById(R.id.imagePrescription);
// Ask for permission for Camera and Storage
if (Build.VERSION.SDK_INT >= 23){
requestPermissions(new String[] {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if camera successfully pops up and takes photo, set photo in ImageView
if (resultCode == RESULT_OK){
if (requestCode == 1){
Bitmap bitmap = BitmapFactory.decodeFile(pathToFile);
imageView.setImageBitmap(bitmap);
}
}
}
// Take Picture button onClick listener
public void takePhoto(View view) {
setPhotoTaken();
}
private void setPhotoTaken() {
Intent takePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Make sure the app can handle our intent
if (takePhoto.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
// Created Photo file
photoFile = createPhotoFile();
// Get path of our photo file
if (photoFile != null) {
pathToFile = photoFile.getAbsolutePath();
Uri photoUri = FileProvider.getUriForFile(Register.this, "com.cognizant.expressprescriptionregistration.fileprovider", photoFile);
takePhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(takePhoto, 1);
}
}
}
// Create the file where the photo will be stored
private File createPhotoFile() {
// Name of file
String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
// Location of storage
File storedDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File photo = null;
try {
// Creates file in storedDir
photo = File.createTempFile(name, ".jpg", storedDir);
} catch (IOException e) {
e.printStackTrace();
}
return photo;
}
// Send to Pharmacy Button
public void sendToPharmacy(View view) {
}
}
答案 0 :(得分:1)
您可以通过从ImageView获取位图来从ImageView获取当前图像:
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
之后,您可以保存并共享位图。