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