- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题在这里已经有了答案:
8年前关闭。
Possible Duplicate:
Calling camera from an activity, capturing an image and uploading to a server
package com.gss.android;
package com.gss.android;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class Pictures extends Activity{
Button btnsave,btnnewpic;
protected ImageView image;
protected String _path;
File sdImageMainDirectory;
private static final int IMAGE_CAPTURE = 0;
protected boolean _taken = true;
private Uri imageUri;
protected static final String PHOTO_TAKEN = "photo_taken";
private static final int CAMERA_PIC_REQUEST = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pictures);
btnsave=(Button)findViewById(R.id.btnsave);
btnnewpic=(Button)findViewById(R.id.btnnewpic);
btnnewpic.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startCameraActivity2();
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ( requestCode == CAMERA_PIC_REQUEST){
if (resultCode == RESULT_OK){
switch (resultCode) {
case 0:
finish();
break;
case -1:
try {
StoreImage(this, Uri.parse(data.toURI()),
sdImageMainDirectory);
Log.e("file path", "stiring file") ;
} catch (Exception e) {
e.printStackTrace();
}
finish();
}
}
} else if ( requestCode == IMAGE_CAPTURE) {
if (resultCode == RESULT_OK){
Log.d("ANDRO_CAMERA","Picture taken!!!");
ImageView image = (ImageView) findViewById(R.id.image);
image.setImageURI(imageUri);
}
}
}
protected void startCameraActivity2()
{
Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
String fileName = "testphoto.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,
"Image capture by camera");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, IMAGE_CAPTURE);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState.getBoolean(Pictures.PHOTO_TAKEN)) {
_taken = true;
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean(Pictures.PHOTO_TAKEN, _taken);
}
public static void StoreImage(Context mContext, Uri imageLoc, File imageDir) {
Bitmap bm = null;
try {
bm = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), imageLoc);
FileOutputStream out = new FileOutputStream(imageDir);
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
Log.e("file dir",imageDir.toString());
bm.recycle();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
最佳答案
我认为这是与模拟器有关的问题,而不是与物理设备有关的问题。
我使用了这段代码,我得到了一个位图:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
captureButton = (Button)findViewById(R.id.capture);
captureButton.setOnClickListener(listener);
imageView = (ImageView)findViewById(R.id.image);
destination = new File(Environment.getExternalStorageDirectory(),"image.jpg");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK) {
//Bitmap userImage = (Bitmap)data.getExtras().get("data");
try {
FileInputStream in = new FileInputStream(destination);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10; //Downsample 10x
Bitmap userImage = BitmapFactory.decodeStream(in, null, options);
imageView.setImageBitmap(userImage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Add extra to save full-image somewhere
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
Toast.makeText(JMABarcodeScannerActivity.this, Uri.fromFile(destination).toString(), Toast.LENGTH_SHORT).show();
startActivityForResult(intent, REQUEST_IMAGE);
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take a Picture"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerInside"
/>
</LinearLayout>
关于android-camera - 使用安卓相机捕捉图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5647572/
如何知道 WM_DEVICECHANGE 的到来? WndProc 被覆盖。我收到了所有消息,但没有一条是 WM_DEVICECHANGE 类型的。 RegisterDeviceNotificatio
我想创建一个滚动的表面列表框,它会在拖动完成后自动捕捉到一个位置,以便屏幕上的中心项目在视口(viewport)中居中。 我已经得到了中心项,但现在像往常一样,WPF 处理大小、屏幕位置和偏移量的方式
如果我有一个使用步长的范围 slider ,例如从 0 到 100,步长为 5,然后我在该范围之间有一个随机值,比如说 56,我如何确定最接近的捕捉值 (55) 是多少? 我正在考虑向前和向后循环,直
我想添加到模块记录器中的所有功能。我想记录函数的“开始”时间和“结束”时间。这样我就可以获得每个函数(同步函数)的执行时间。 但我不知道如何让它工作.. =(我不想以某种动态方式重写函数 - 我想在将
我正在编写一个 C# 应用程序,如果文件已被某个进程使用,我必须在其中显示一条消息,如果该文件不存在,则应用程序需要显示另一条消息。 像这样: try { //Code to open a f
所以我正在使用城市词典 api,他们的术语可以链接到其他使用 [term] 和 api 的框,我想使它们实际上在 markdown 中超链接,即 term所以我尝试制作一个替换正则表达式来做到这一点我
我有一个使用鼠标滚轮 jQuery 插件的水平滚动网站。滚动有效,但我想将每个“文章”捕捉到文档的左侧,这样一旦停止滚动,它就不会停留在一半的位置。 我目前的标记: CSS #viewport { w
我需要在 windows 上录制声音。我需要写信来传输我从演讲者那里听到的内容。我可以依赖什么方法/API? 最佳答案 您可以使用 DirectSound ;可以找到 sample here这是针对麦
for ii = 1:2:2*de.nP G=[one, aux3(:,ii), aux3(:,ii) - aux2(:,ii),aux3(:,ii+1) - a
您好,感谢阅读。我是编程、C# 和套接字编程方面的新手。在我的代码中,我尝试发现问题以在我的应用程序中提供容错能力。以下内容: catch (ArgumentNullException
我有一个函数可以运行用户生成的正则表达式。但是,如果用户输入了一个不会运行的正则表达式,那么它就会停止并跌倒。我试过将行包装在 Try/Catch block 中,但是没有任何反应。 如果有帮助,我正
嵌套的 Try/Catch 是否表示您的编码不干净?我想知道,因为在我的 catch 中,我正在调用另一个方法,如果失败,我会收到另一个运行时错误,所以我很想再次使用另一个 try/catch 将这些
我不知道如何放置一个相对于其同级路径边界框的路径。想象一个像窗口一样的盒子,我想在它的右上角放一个关闭按钮。这是在变换窗口(缩放 3 倍)后组合在一起的框和关闭按钮: 我只是在
我正在尝试使用 UISlider 实现某种形式的捕捉或步骤。我编写了以下代码,但它并没有像我希望的那样顺利。它可以工作,但是当我向上滑动它时,它会向右移动 5 个点,使手指不在“滑动圆”的中心 这是我
目前,我使用 Snap SVG 创建一个小型建模工具。 var p = Snap.path(pathString).attr({fill:'none', stroke:'black', strokeW
我希望能够使用 Snap SVG 将一组集合作为一个组进行拖动。到目前为止,我只能将子集(矩形和文本框)作为一个项目进行拖动,但我想要实现的是集体“表格”是可拖动的,而其中的字段仍保留为单独的形状,因
我有一段代码可以像这样抛出和捕获错误 try { } catch (e: FooException) { } catch (e: BarException) { } finally { } 并且有一些
我定义了一个自定义错误处理程序,它捕获所有异常并将它们保存到日志中。现在,如果我在 mysqli 查询中出现语法错误,例如拼写错误,页面会在此时完全停止加载。不会引发异常,因此不会触发错误处理程序,也
我有以下分组的svg文件,g的id为flower-petals,然后里面的每个部分都是花瓣,我似乎无法更改每个内部路径的填充。 我将 snap 的 petals 变量定义为 petals.Snap("
当脚本执行 Read-Host cmdlet,关闭窗口不会激活 finally堵塞。下面是一个随意但功能最少的示例。我正在使用 PowerShell 5.0。 Beep() 只是为了让 finally
我是一名优秀的程序员,十分优秀!