Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Android Image

+. Intent buat camera


Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+. capture gambar dalam Bitmap
Bundle extra = intent.getExtra();
Bitmap bmp = (Bitmap) extra.get("data");
iv.setImageBitmap(bmp);
+. Capture gambar besar
menggunakan EXTRA_OUTPUT pada MediaStore
//note: gambar harus disimpan dalam microSD
String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath
()
+ "/myfavoritepicture.jpg";
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_RESULT);
+. Menampilkan Gambar yang besar
Menggunakan class BitmapFactory
membuat sample image untuk dipreview, contohnya sample image 1/8 dari image asli
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inSampleSize = 8;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
imv.setImageBitmap(bmp);
mendapatkan ukuran layar
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();
mendapatkan ukuran image
// Load up the image's dimensions not the image itself
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw);
Log.v("HEIGHTRATIO",""+heightRatio);
Log.v("WIDTHRATIO",""+widthRatio);
share image ke aplikasi lain dengan menggunakan content provider

===========================================
ADVANCED CAMERA
===========================================
Untuk menggunakan kamera harus menggunakan permission <uses-permission android:n
ame="android.permission.CAMERA" />
Untuk menampilkan image pada class Camera menggunakan SurfaceView
SurfaceView cameraView = (CameraView) this.findViewById(R.id.CameraView);
SurfaceHolder surfaceHolder = cameraView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Kita membuat inteface implements SurfaceHolder.Callback agar bisa memasukkan fun
gsi saat event Surface terjadi
ubah display ke landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mengambil parameter orientasi pada kamera
Camera.Parameters parameters = camera.getParameters();
parameters.set("some parameter", "some value");
// or
parameters.set("some parameter", some_int);
camera.setParameters(parameters);

You might also like