Camera etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Camera etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

24 Ekim 2017 Salı

Camera Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.hardware.Camera;
Şu izinler gerekir.
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
Bu sınıf deprecate edildi. CameraDevice sınıfını kullanmak gerekir.

flash özelliği
Camera'nın flash desteği olduğu şöyle anlaşılır.
boolean isSupportFlash = getApplicationContext().getPackageManager().
 hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Flash şöyle açılır
Parameters params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
Flash şöyle kapatılır
Parameters params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
getInfo metodu
Şöyle yaparız.
public int getOrientation(final int cameraId) {
  Camera.CameraInfo info = new Camera.CameraInfo();
  Camera.getCameraInfo(cameraId, info);
  return info.orientation;
}
getParameters metodu
Camera.Parameters nesnesi döner. Şöyle yaparız.
Parameters params = camera.getParameters();
open metodu
Ön kamera şöyle açılır.
Camera camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
Arka kamera şöyle açılır.
Camera camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
release metodu
şöyle yaparız.
camera.release();
startPreview metodu
Şöyle yaparız.
camera.startPreview();
stopPreview metodu
Şöyle yaparız.
camera.stopPreview();
takePicture metodu
Şöyle yaparız.
Camera.PictureCallback pictureCallback = new PictureCallback() {
  @Override
  public void onPictureTaken(byte[] data, Camera camera) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, options);
  }
};
camera.takePicture(null, null, pictureCallback);

8 Şubat 2017 Çarşamba

Camera.Parameters Sınıfı

Giriş
Şu satırı dahil ederiz.
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
constructor
Şöyle yaparız.
Parameters params = camera.getParameters();
getExposureCompensation metodu
Şöyle yaparız.
int exposureComp = params.getExposureCompensation();
getPreviewSize metodu
Açıklaması şöyle
Picture size This is the size of the image produced when you tell the camera to take a photo. If it is the same aspect ratio as the native resolution then it will be directly scaled from that. If the aspect ratio is different then it will be cropped from the native size. In my experience, the largest size returned by getSupportedPictureSizes is the native resolution of the camera.

Preview size This is the size of the image preview that is shown on-screen. It may be a different aspect ratio than either the native size or the picture size, causing further cropping
Şöyle yaparız.
Camera.Size size = params.getPreviewSize();
set metodu
Şöyle yaparız.
params.set("rotation", 90); 
setFlashMode metodu
Şöyle yaparız.
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
Şöyle yaparız.
params.setFlashMode(Parameters.FLASH_MODE_OFF);
setPictureFormat metodu
Şöyle yaparız
params.setPictureFormat(ImageFormat.JPEG);
setPictureSize metodu
Örnek ver

setPreviewSize metodu
Örnek ver