÷ºÎ ÀÚ·á´Â °Ö·°½ÃS¿¡¼ Å×½ºÆ®ÇÑ ¼Ò½ºÀÔ´Ï´Ù.
»çÁøÂï´Â ±â´É°°Àº°Ç ¾ø½À´Ï´Ù. ¼øÀüÀÌ Ä«¸Þ¶ó ¿ÀDZâ´É¸¸ ÇÕ´Ï´Ù.
ÀÎÅͳݿ¡ µµ´Â ¼Ò½º¸¦ »ç¿ëÇÏ´Ï Á¦´ë·Î µ¿ÀÛÀÌ ¾ÈµÅ¾î ÀÌ·±Àú·± ¼Ò½º¸¦ Âü°íÇؼ
º¯°æ ÀÛ¾÷ÇÑ °ÍÀÔ´Ï´Ù. µ¿ÀÛ µÊ!! ^^;
ÁÖ¼® 󸮸¦ ÇÏÁö ¾ÊÀº ÀÌÀ¯´Â... ±âº»ÀûÀÎ ³»¿ëÀº ±×³É °¡Á®´Ù ¾²¸é µÈ´Ù¶ó°í »ý°¢ÇؼÀÔ´Ï´Ù.
¾ÆÁ÷Àº ´Ùµé Àú·¸°Ô ¾²´Ï±ñ... << À̶õ ÀÌÀ¯¹Û¿¡ ¾ÈµË´Ï´Ù ^^; Áö½Ä ºÎÁ·...
°Ë»öÀº Camera.open() << ÀÌ ´Ü¾î·Î °Ë»öÇÏ¸é ¸î°¡Áö ÀÚ·á°¡ ³ª¿É´Ï´Ù.
package com.Zooms;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import java.io.IOException;
import java.util.List;
// ----------------------------------------------------------------------
// <uses-permission android:name="android.permission.CAMERA"/> ÆÛ¹Ì¼Ç Ãß°¡
public class main extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
}
/*
* ¾Æ·¡ ó·³ Ãß°¡ÇÏ¸é »çÁøÂï±â°¡ °¡´ÉÇϴٴ±º¿ä ^^;
* Á¦°¡ ¸¸µç ¼Ò½º´Â ¼øÀüÈ÷ Ä«¸Þ¶ó¸¦ ¿ÀÇÂÇÏ´Â ±â´ÉÀÔ´Ï´Ù.
* ³ª¸ÓÁö ±â´ÉÀº °³ÀÎÀÌ °øºÎÇغ¸½Ã°í Àúµµ ¸¸µé¾îº¸´Âµ¥·Î ¿Ã¸®°Ú½À´Ï´Ù.
* private Preview preview;
*
* preview = new Preview(this);
*
* buttonClick.setOnClickListener(new OnClickListener(){
* public void onClick(View v){
* preview.getCamera().takePicture(shutterCallback, rawCallback, jpegCallback);
* }
* });
*
*/
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
Preview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public Camera getCamera(){
return mCamera;
}
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
// mCamera.setPreviewCallback(new PreviewCallback());
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h){
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double)w/h;
if (sizes == null){
return null;
}
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Size size : sizes){
double ratio = (double)size.width/size.height;
if(Math.abs(ratio-targetRatio) > ASPECT_TOLERANCE){
continue;
}
if(Math.abs(size.height - targetHeight) < minDiff){
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
if (optimalSize == null){
minDiff = Double.MAX_VALUE;
for (Size size : sizes){
double ratio = (double)size.width/size.height;
if(Math.abs(size.height - targetHeight) < minDiff){
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
}
±¦ÂúÀº Âü°í ºí·Î±× ÀÔ´Ï´Ù
http://blog.naver.com/agapeuni?Redirect=Log&logNo=60104914002