I am working on a small android image processing project.
Earlier I was testing my code on Samsung Galaxy Ace and the code was fine.
Now I have got a new phone Samsung Galaxy grand which has 8 megapixel camera and Android jellybean.
The image quality has reduced very much. It seems the camera isn't autofoccsing.
I tried many tutorials on auto focus but the image quality remains the same
Screenshot: http://wikisend.com/download/527870/device-2013-02-12-181021.png
public class TrackLaser extends Activity {
private Preview mPreview;
private DrawOnTop mDrawOnTop;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
// Hide the window title.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
// Create our DrawOnTop view.
mDrawOnTop = new DrawOnTop(this);
mPreview = new Preview(this, mDrawOnTop);
setContentView(mPreview);
addContentView(mDrawOnTop, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
}
@SuppressLint("DrawAllocation")
class DrawOnTop extends View {
Bitmap mBitmap;
Paint mPaintBlack;
Paint mPaintYellow;
Paint mPaintRed;
Paint mPaintWhite;
Paint mPaintGreen;
Paint mPaintBlue;
byte[] mYUVData;
int[] mRGBData;
int x,y;
int mImageWidth, mImageHeight;
public DrawOnTop(Context context) {
super(context);
mBitmap = null;
mYUVData = null;
mRGBData = null;
}
@Override
protected void onDraw(Canvas canvas) {
//
}
// end onDraw method
static public void decodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height) {
//
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
DrawOnTop mDrawOnTop;
boolean mFinished;
Preview(Context context, DrawOnTop drawOnTop) {
super(context);
mDrawOnTop = drawOnTop;
mFinished = false;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
}
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
mCamera.autoFocus(myAutoFocusCallback);
// Preview callback used whenever new viewfinder frame is available
mCamera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera)
{
if ( (mDrawOnTop == null) || mFinished )
return;
if (mDrawOnTop.mBitmap == null)
{
// Initialize the draw-on-top companion
Camera.Parameters params = camera.getParameters();
mDrawOnTop.mImageWidth = params.getPreviewSize().width;
mDrawOnTop.mImageHeight = params.getPreviewSize().height;
mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight, Bitmap.Config.RGB_565);
mDrawOnTop.mRGBData = new int[mDrawOnTop.mImageWidth * mDrawOnTop.mImageHeight];
mDrawOnTop.mYUVData = new byte[data.length];
}
// Pass YUV data to draw-on-top companion
System.arraycopy(data, 0, mDrawOnTop.mYUVData, 0, data.length);
mDrawOnTop.invalidate();
}
});
}
catch (IOException exception) {
mCamera.release();
mCamera = null;
}
}
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.
mFinished = true;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
mCamera.setParameters(parameters);
mCamera.startPreview();
mCamera.autoFocus(myAutoFocusCallback);
}
AutoFocusCallback myAutoFocusCallback = new AutoFocusCallback(){
public void onAutoFocus(boolean arg0, Camera arg1) {
Log.w("myApp", "AUTOFOCUSSED");
}};
}