不能'根据相机意图以最大分辨率保存图像

发布于 2024-10-18 14:28:27 字数 1298 浏览 2 评论 0原文

我正在通过意图打开相机并尝试将图像保存到 SDCard 中的文件夹中。我可以拍摄图像并且图像正在保存。

但问题是正在存储缩略图分辨率图像(160*120)大小的图像。

这就是我正在做的...

打开相机

mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI
                    .toString());
    mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
    startActivityForResult(mIntent, PHOTO_SELECT);

和活动以获得结果...

imageFileFolder = new File(Environment.getExternalStorageDirectory(),
            "MyApp");
    FileOutputStream out = null;
    Calendar c = Calendar.getInstance();
    String date = fromInt(c.get(Calendar.MONTH))
            + fromInt(c.get(Calendar.DAY_OF_MONTH))
            + fromInt(c.get(Calendar.YEAR))
            + fromInt(c.get(Calendar.HOUR_OF_DAY))
            + fromInt(c.get(Calendar.MINUTE))
            + fromInt(c.get(Calendar.SECOND));
    imageFileName = new File(imageFileFolder, date.toString() + ".jpg");

    try
    {
        out = new FileOutputStream(imageFileName);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        scanPhoto(imageFileName.toString());
        out = null;

任何人都可以帮助存储我正在拍摄的高分辨率图像...

I am taking opening the camera through intents and trying to save the image into a folder in SDCard. I can take the image and the image is getting saved.

But the problem is that is getting stored a thumbnail resolution image (160*120) size image.

This is what i am doing...

To open Camera

mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI
                    .toString());
    mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
    startActivityForResult(mIntent, PHOTO_SELECT);

And on Activity for result ...

imageFileFolder = new File(Environment.getExternalStorageDirectory(),
            "MyApp");
    FileOutputStream out = null;
    Calendar c = Calendar.getInstance();
    String date = fromInt(c.get(Calendar.MONTH))
            + fromInt(c.get(Calendar.DAY_OF_MONTH))
            + fromInt(c.get(Calendar.YEAR))
            + fromInt(c.get(Calendar.HOUR_OF_DAY))
            + fromInt(c.get(Calendar.MINUTE))
            + fromInt(c.get(Calendar.SECOND));
    imageFileName = new File(imageFileFolder, date.toString() + ".jpg");

    try
    {
        out = new FileOutputStream(imageFileName);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        scanPhoto(imageFileName.toString());
        out = null;

Can anyone please help in storing the high resolution image that i am taking...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以歌曲疗慰 2024-10-25 14:28:27

我认为你使用以下类来捕获图像它保存图像和图像分辨率
取决于您的相机MP...可能是..

public class CameraApplication extends Activity implements
        SurfaceHolder.Callback {
    private static final String TAG = "cookbook.hardware";
    private LayoutInflater mInflater = null;
    Camera mCamera;
    byte[] tempdata;
    boolean mPreviewRunning = false;
    private SurfaceHolder mSurfaceHolder;
    private SurfaceView mSurfaceView;
    Button takepicture;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);

    mSurfaceView = (SurfaceView) findViewById(R.id.surface);

    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mInflater = LayoutInflater.from(this);

    View overView = mInflater.inflate(R.layout.cameraoverlay, null);
    this.addContentView(overView, new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    takepicture = (Button) findViewById(R.id.button);

    takepicture.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            mCamera.takePicture(mShutterCallback, mPictureCallback, mjpeg);
        }
    });
}

ShutterCallback mShutterCallback = new ShutterCallback() {
    @Override
    public void onShutter() {
    }
};
PictureCallback mPictureCallback = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
    }
};
PictureCallback mjpeg = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
        if (data != null) {
            tempdata = data;
            done();
        }
    }
};

void done() {
    Bitmap bm = BitmapFactory.decodeByteArray(tempdata, 0, tempdata.length);
    String url = Images.Media.insertImage(getContentResolver(), bm, null,
            null);
    bm.recycle();
    Bundle bundle = new Bundle();
    if (url != null) {
        bundle.putString("url", url);
        Intent mIntent = new Intent();
        mIntent.putExtras(bundle);
        setResult(RESULT_OK, mIntent);
    } else {
        Toast
                .makeText(this, "Picture can not be saved",
                        Toast.LENGTH_SHORT).show();
    }
    finish();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    Log.e(TAG, "surfaceChanged");
    try {
        if (mPreviewRunning) {
            mCamera.stopPreview();
            mPreviewRunning = false;
        }
        Camera.Parameters p = mCamera.getParameters();
        p.setPreviewSize(w, h);
        mCamera.setParameters(p);
        mCamera.setPreviewDisplay(holder);
        mCamera.startPreview();
        mPreviewRunning = true;
    } catch (Exception e) {
        Log.d("", e.toString());
    }
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    Log.e(TAG, "surfaceCreated");
    mCamera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    Log.e(TAG, "surfaceDestroyed");
    mCamera.stopPreview();
    mPreviewRunning = false;
    mCamera.release();
    mCamera = null;
}
}

main.xmlcameraoverlay.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <SurfaceView android:id="@+id/surface"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
    </SurfaceView>
</LinearLayout>

....

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:gravity="bottom"
    android:layout_gravity="bottom">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="horizontal" android:gravity="center_horizontal">
        <Button android:id="@+id/button" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="take picture" />
    </LinearLayout>
</LinearLayout>

并且不要忘记相机用户权限

<uses-permission android:name="android.permission.CAMERA"></uses-permission>

可能在您的应用程序中工作

i think you use following class for capture image it's save image and image resolution
depend on your camera MP...may be..

public class CameraApplication extends Activity implements
        SurfaceHolder.Callback {
    private static final String TAG = "cookbook.hardware";
    private LayoutInflater mInflater = null;
    Camera mCamera;
    byte[] tempdata;
    boolean mPreviewRunning = false;
    private SurfaceHolder mSurfaceHolder;
    private SurfaceView mSurfaceView;
    Button takepicture;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);

    mSurfaceView = (SurfaceView) findViewById(R.id.surface);

    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mInflater = LayoutInflater.from(this);

    View overView = mInflater.inflate(R.layout.cameraoverlay, null);
    this.addContentView(overView, new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    takepicture = (Button) findViewById(R.id.button);

    takepicture.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            mCamera.takePicture(mShutterCallback, mPictureCallback, mjpeg);
        }
    });
}

ShutterCallback mShutterCallback = new ShutterCallback() {
    @Override
    public void onShutter() {
    }
};
PictureCallback mPictureCallback = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
    }
};
PictureCallback mjpeg = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera c) {
        if (data != null) {
            tempdata = data;
            done();
        }
    }
};

void done() {
    Bitmap bm = BitmapFactory.decodeByteArray(tempdata, 0, tempdata.length);
    String url = Images.Media.insertImage(getContentResolver(), bm, null,
            null);
    bm.recycle();
    Bundle bundle = new Bundle();
    if (url != null) {
        bundle.putString("url", url);
        Intent mIntent = new Intent();
        mIntent.putExtras(bundle);
        setResult(RESULT_OK, mIntent);
    } else {
        Toast
                .makeText(this, "Picture can not be saved",
                        Toast.LENGTH_SHORT).show();
    }
    finish();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    Log.e(TAG, "surfaceChanged");
    try {
        if (mPreviewRunning) {
            mCamera.stopPreview();
            mPreviewRunning = false;
        }
        Camera.Parameters p = mCamera.getParameters();
        p.setPreviewSize(w, h);
        mCamera.setParameters(p);
        mCamera.setPreviewDisplay(holder);
        mCamera.startPreview();
        mPreviewRunning = true;
    } catch (Exception e) {
        Log.d("", e.toString());
    }
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    Log.e(TAG, "surfaceCreated");
    mCamera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    Log.e(TAG, "surfaceDestroyed");
    mCamera.stopPreview();
    mPreviewRunning = false;
    mCamera.release();
    mCamera = null;
}
}

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <SurfaceView android:id="@+id/surface"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
    </SurfaceView>
</LinearLayout>

cameraoverlay.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical" android:gravity="bottom"
    android:layout_gravity="bottom">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="horizontal" android:gravity="center_horizontal">
        <Button android:id="@+id/button" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="take picture" />
    </LinearLayout>
</LinearLayout>

and don't forget camera user permission

<uses-permission android:name="android.permission.CAMERA"></uses-permission>

may work in your application....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文