- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要我在另一项 Activity 中拍摄并展示的照片。我最好希望有一个用于下一个 Activity 的按钮,单击时会显示我拍摄的图像。只需要一个简单的方法。我是 android studio 的新手,因此我不太确定如何解决这个问题。
这是我的代码
package mapp.com.sg.receiptscanner;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class Scanner extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
Button btnCamera = (Button)findViewById(R.id.btnCamera);
imageView = (ImageView)findViewById(R.id.imageView);
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
public void onClick(View view) {
Intent i = new Intent(this, Info.class);
startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context="mapp.com.sg.receiptscanner.Scanner">
<ImageView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="9"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#1f4991"
android:textColor="@android:color/white"
android:text="Open Camera"
android:id="@+id/btnCamera"
android:layout_marginBottom="14dp"
android:layout_above="@+id/ProceedBtn"
android:layout_alignStart="@+id/ProceedBtn" />
<Button
android:id="@+id/ProceedBtn"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Proceed"
android:background="#1f4991"
android:textColor="@android:color/white"
android:onClick="onClick"/>
最佳答案
尝试将您的照片转换为字节并将其发送到另一个 Activity 。
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image = stream.toByteArray();
Intent intent = new Intent(this, YourActivity.class);
intent.putExtra("photo", image);
startActivity(intent);
并在下一个 Activity 中获取它并使用decodeByteArray创建位图并设置到 ImageView 中。
YourActivity.class
byte[] byteArrayExtra = getIntent().getByteArrayExtra("photo");
//BitmapOptions is optional you can create bitmap without this also. This is the description of its use from google developer docs.
//BitmapFactory.Options: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned.
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArrayExtra, 0, byteArrayExtra.length, new BitmapFactory.Options());
//or
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArrayExtra, 0, byteArrayExtra.length);
imageview.setimageBitmap(bitmap);
关于java - 拍照后如何在另一个 Activity 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45678008/
所以我对 Cordova 还很陌生,现在我正在使用它来制作一个应用程序,我正在尝试拍照然后保存它。现在我还不能拍照。我所拥有的只是一个按钮,在相应的 javascript 文件中,按下按钮时会调用一个
我有完整的工作代码来拍照、裁剪、发送带有图像附件的电子邮件。 代码流程如下:拍张照片 > 找到并选择我们刚刚从图库中拍摄的照片> 裁剪它 > 通过电子邮件发送附件。 我想了解如何跳过整个“查找并选择我
我是编程新手,正在尝试使用板载摄像头硬件制作应用程序,我的目的是拍照;然后,当您单击“保存”时,该图片将出现在要编辑的新 Activity 中...我已经研究了几天如何最好地使用相机硬件...有人告诉
有没有一种方法可以使用 UIImagePickerController 中的叠加层来显示用户可能使用的方形图片,同时在某处有一个切换按钮可以即时切换? 目前 iOS 7 相机有这个功能,但是 UIIm
当我点击 GestureDetector 时,它会打开一个对话框,我可以在其中选择是要从图库中拍摄照片还是要自己制作照片 (the plugin)。但我的问题是当我点击对话框中的一个按钮时,对话框再次
我的一个页面上有一个 map 控件,我想拍一张照片并将其显示在不同的屏幕上。有谁知道我怎么能做到这一点? map 在 内. 最佳答案 您应该使用 WriteableBitmap 类的 Render
我一直在构建一个使用 Flurge 的 CameraKit 的项目,但我遇到了一个相当烦人的问题。其实我不知道怎么拍照。我有一个快门按钮,按下该按钮应该会激活 OnPicturetaken Liste
当我启动照片捕捉 Intent 时,返回给我的照片路径是:content://media/external/images/media/40209 但是当我查看我的设备时,照片路径应该类似于 [..]/
我结账Camera2Basic (谷歌样本) 我刚刚在类 Camera2BasicFragment 中更改了这个方法为了用前置摄像头拍照: private void setUpCameraOutp
在 fragment 中我想拍照但是我遇到了问题,我从来没有得到 onActivityResult 的回调 我的代码: private void dispatchTakePictureIntent(
当我使用 UIImagePicker 从相机拍照时,背景音乐(来自 ipod 应用程序、pandora 应用程序)停止。 Facebook 应用程序不会发生这种情况。有单独的代表来做这件事吗?请帮忙
我用这个方法拍了一张照片。 func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{ le
在我的 chrome 上,以下代码仅打开相机并立即崩溃,即显示黑屏。这段代码在 Firefox 上运行良好。为什么? http://jsfiddle.net/2mLb6cs2/ (function()
我正在尝试在我的 iOS 应用程序中实现 OpenCV。 CvVideoCamera 很棒,因为它有一个委托(delegate)方法,可以让我处理相机预览的每一帧,但我不知道如何提取一帧并将其保存为图
当我想使用相机拍照时,CameraSource 出现了一些问题。我想要的只是用我在 xml 文件上制作的按钮拍照并使用“CameraSource”拍照,因为我也在使用“TextRecognizer”。
可以禁用/删除此照片确认对话框: 我需要以某种方式跳过此对话框,但我仍想使用 Intent。我找到了这个 android: Take camera picture without "save" / "
我正在使用 FileProvider 在 Android Nougat 上拍照,这是我的代码 文件路径.xml: Java: String fileName =
将文件路径额外添加到图像捕获 Intent 会导致相机应用程序在 TF300t Android 平板电脑上出现故障,系统版本为 4.2.1。按“完成”按钮什么都不做——甚至不关闭相机应用程序 Acti
我正在构建一个将跟踪库存的网络内联网应用程序,我希望能够使用 iPad 的内置相机为每件元素拍照。这可能吗? 我已经使用应用对条形码做了类似的事情,但我还没有找到任何可以对照片做同样事情的东西。 最佳
我用这个方法拍了一张照片。 func convertImageFromCMSampleBufferRef(sampleBuffer:CMSampleBuffer) -> CIImage{ le
我是一名优秀的程序员,十分优秀!