2
我正在制作像Whats应用程序一样的自定义相机。当我打开自定义相机时,它显示屏幕与wats应用程序相同。单击图片后显示相机图像预览
当我点击的形象,我需要显示预览喜欢什么应用程序在下面给出image.i不知道什么机制WHATS应用程序使用,以显示预览
*注 - Whats应用程序使用图像视图来设置位图来显示图片预览或其他复杂的方式。
我正在制作像Whats应用程序一样的自定义相机。当我打开自定义相机时,它显示屏幕与wats应用程序相同。单击图片后显示相机图像预览
当我点击的形象,我需要显示预览喜欢什么应用程序在下面给出image.i不知道什么机制WHATS应用程序使用,以显示预览
*注 - Whats应用程序使用图像视图来设置位图来显示图片预览或其他复杂的方式。
我只是给你一个工作的想法WhatsApp在捕获背景做什么。
答案的结果,更改版面设计作为首选,我的设计是基本的。
camera_preview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_weight="1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_gravity="center_horizontal"
android:hint="Add a caption...."
android:textColorHint="#999999"
android:background="#333333"
android:padding="10dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/cancel"
android:layout_weight="1"
android:textColor="#ffffff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Okay"
android:id="@+id/okay"
android:layout_weight="1"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
和class
Preview.java作为
public class Preview extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera_preview);
ImageView image=(ImageView)findViewById(R.id.imageView);
Intent data=getIntent();
File imgFile = new File(data.getStringExtra("path"));
//Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int screenWidth = size.x;
int screenHeight = size.y;
// Get target image size
Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
int bitmapHeight = bitmap.getHeight();
int bitmapWidth = bitmap.getWidth();
// Scale the image down to fit perfectly into the screen
// The value must be adjusted for phone/tables displays
while (bitmapHeight > (screenHeight) && bitmapWidth > (screenWidth)) {
bitmapHeight = bitmapHeight/2;
bitmapWidth = bitmapWidth/2;
}
// Create resized bitmap image
BitmapDrawable resizedBitmap = new BitmapDrawable(getResources(),
Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight,
false));
image.setImageDrawable(resizedBitmap);
}
public void onCancelClick(View v){
}
public void onOkayClick(View v){
}
从您的主要活动startCamera
通过
public void startCamera(){
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, 2);
}
声明String path
全球veriable
内onCreate
方法
path = Environment.getExternalStorageDirectory() + "/example.jpg";
我开始了相反startring活动的结果,活动你 可以只显示一个对话框,
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2 && resultCode == RESULT_OK) {
Intent startPreview = new Intent(this, Preview.class);
startPreview.putExtra("path", path);
startActivity(startPreview);
}
super.onActivityResult(requestCode, resultCode, data);
}
我不认为最新的应用程序与您在上面解释的相同。 – 2015-03-03 10:54:45
是的你写,最新的应用程序创建自定义相机,然后创建自定义布局的结果,然后显示图像,如果你不明白,我会张贴代码。 – IshRoid 2015-03-03 11:09:37
请邮编。我会很高兴的。我很高兴看到。主要问题是我不想在预览图像中看到任何延伸。 – 2015-03-03 11:17:09