如何设置相机应用程序
How to set a camera app
我正在尝试制作一个相机应用程序,它可以拍摄照片并允许用户将其设置为墙纸,唯一的错误是
04-23 10:39:11.950 571-571/? E/Vold: Error reading configuration (No such file or directory)... continuing anyways
这是我的 java 代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button b1,b2;
ImageView iv;
Intent i;
final static int camdata=0;
Bitmap bmp;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
InputStream is =context.getResources().openRawResource(+R.drawable.wale);
bmp= BitmapFactory.decodeStream(is);
}
private void initialize(){
iv =(ImageView)findViewById(R.id.imageView);
b1=(Button)findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button:
WallpaperManager myWallpaper =WallpaperManager.getInstance(this);
try{
myWallpaper.setBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.button2:
i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,camdata);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RESULT_OK){
Bundle extras =data.getExtras();
bmp=(Bitmap)extras.get("data");
iv.setImageBitmap(bmp);
}
}
}
我的xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.union.test5.MainActivity"
tools:showIn="@layout/activity_main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Wallpaper"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera"
android:id="@+id/button2"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_above="@+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
I have set the image in my drawable file wale .
我不知道这里缺少什么目录程序正在正确编译并且没有给出任何错误但它正在提供运行时 error.What 它需要的更改
Inputstream命令设置错误or
InputStream is =context.getResources().openRawResource(+ R.drawable.wale);
bmp= BitmapFactory.decodeStream(is);
这是主要错误。
从中删除上下文
InputStream 是=context.getResources().openRawResource(+ R.drawable.wale);
bmp= BitmapFactory.decodeStream(是);
我正在尝试制作一个相机应用程序,它可以拍摄照片并允许用户将其设置为墙纸,唯一的错误是
04-23 10:39:11.950 571-571/? E/Vold: Error reading configuration (No such file or directory)... continuing anyways
这是我的 java 代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button b1,b2;
ImageView iv;
Intent i;
final static int camdata=0;
Bitmap bmp;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
InputStream is =context.getResources().openRawResource(+R.drawable.wale);
bmp= BitmapFactory.decodeStream(is);
}
private void initialize(){
iv =(ImageView)findViewById(R.id.imageView);
b1=(Button)findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button:
WallpaperManager myWallpaper =WallpaperManager.getInstance(this);
try{
myWallpaper.setBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.button2:
i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,camdata);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==RESULT_OK){
Bundle extras =data.getExtras();
bmp=(Bitmap)extras.get("data");
iv.setImageBitmap(bmp);
}
}
}
我的xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.union.test5.MainActivity"
tools:showIn="@layout/activity_main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Wallpaper"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera"
android:id="@+id/button2"
android:layout_above="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="73dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_above="@+id/button2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
I have set the image in my drawable file wale .
我不知道这里缺少什么目录程序正在正确编译并且没有给出任何错误但它正在提供运行时 error.What 它需要的更改 Inputstream命令设置错误or
InputStream is =context.getResources().openRawResource(+ R.drawable.wale);
bmp= BitmapFactory.decodeStream(is);
这是主要错误。
从中删除上下文 InputStream 是=context.getResources().openRawResource(+ R.drawable.wale); bmp= BitmapFactory.decodeStream(是);