【问题标题】:How to attach the pictures that I take using the camera in my application?如何在我的应用程序中附加使用相机拍摄的照片?
【发布时间】:2012-03-31 16:28:51
【问题描述】:

我正在开发一个应用程序,在该应用程序中我使用一个按钮来加载相机并需要在我的应用程序中附加这些图片。我在加载相机时没有问题,但我无法在我的应用程序中附加使用相机拍摄的那些照片。谁能给出一个好的解决方案?

谢谢(提前) Swetha Kaulwar。

【问题讨论】:

  • 在我创建的应用程序中。
  • 您想在 imageview 中显示该图像吗?或者你想为你的应用程序存储它?
  • 你尝试过什么代码来启动原生相机?
  • 我不想显示图像。例如在 G-mail 中我们附加文件对吗?我想将我的图像保存为加载相机按钮下方的附件。
  • Paresh 你能告诉我如何发送我的代码。因为它既不允许我编辑我的帖子,也不允许我通过添加评论发送。是否有任何其他方式来发送代码。

标签: java android android-layout android-emulator android-widget


【解决方案1】:

我在我的 onActivityResult 中执行此操作...我从捕获意图中获取图片减小其大小并将其添加到列表中,该列表稍后添加到自定义列表视图中...我希望这对您的问题有所帮助

if (resultCode == Activity.RESULT_OK) {

            Bundle extras = intent.getExtras();
            Bitmap bitmap = (Bitmap) extras.get("data");


             int width = bitmap.getWidth();
             Log.i("size width:", String.valueOf(width));
             int height = bitmap.getHeight();
             Log.i("size height:", String.valueOf(height));

             float widthPercent = (float) 0.8;
             float heightPercent = (float) 0.8;

             float newWidth = bitmap.getWidth() * widthPercent;
             float newHeight = bitmap.getHeight() * heightPercent;

             while (newWidth > 250 || newHeight > 250) {

             newWidth = newWidth * widthPercent;
             Log.i("size width:", String.valueOf(newWidth));
             newHeight = newHeight * heightPercent;
             Log.i("size height:", String.valueOf(newHeight));
             }




             // calculate the scale - in this case = 0.4f
             float scaleWidth = ((float) newWidth) / width;
             Log.i("new size width:", String.valueOf(scaleWidth));
             float scaleHeight = ((float) newHeight) / height;
             Log.i("new size height:", String.valueOf(scaleHeight));

             Matrix matrix = new Matrix();

             // resize the bit map
             matrix.postScale(scaleWidth, scaleHeight);

             // recreate the new Bitmap
             Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
             width, height, matrix, true);

             Log.i("new bitmap width:",
             String.valueOf(resizedBitmap.getWidth()));
             Log.i("new bitmap height:",
             String.valueOf(resizedBitmap.getHeight()));

            App.serviceCallImages.add(resizedBitmap);

            Adapter.notifyDataSetChanged();

            break;
        }

这是我的相机意图代码

public void OnCameraOpen(View v) {

    if (App.serviceCallImages.size() < 2) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        startActivityForResult(intent, CAPTURE_PICTURE_INTENT);
    } else {
        Toast.makeText(getApplicationContext(),    getString(R.string.MaxPics),
                Toast.LENGTH_SHORT).show();
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    相关资源
    最近更新 更多