拍照与Android的问题(垂直相机|人像) [英] Issues taking picture with Android (Vertical Camera | Portrait)
本文介绍了拍照与Android的问题(垂直相机|人像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过以下code显示了相机的preVIEW垂直和它的作品.. 但!!我得到的风景照片! :(
我怎么可以垂直构建呢? 我在垂直preVIEW看法,但我不能将图片保存垂直。
问候和感谢, 弗兰
ONCLICK
公共无效的onClick(查看为arg0){
camera.takePicture(myShutterCallback,myPictureCallback_RAW,myPictureCallback_JPG);
}
preVIEW
@覆盖
公共无效surfaceChanged(SurfaceHolder持有人,INT格式,诠释的宽度,
INT高度){
如果(previewing){
camera.stop preVIEW();
previewing = FALSE;
}
如果(相机!= NULL){
/ *
* camera.set previewDisplay(surfaceHolder); camera.start preVIEW();
* previewing = TRUE;
* /
Camera.Parameters参数= camera.getParameters();
parameters.set previewSize(宽,高);
camera.setParameters(参数);
// Condicions每utilitzar拉orientacio adecuada segons埃尔SDK
如果(的Integer.parseInt(Build.VERSION.SDK)> = 8)
setDisplayOrientation(摄像头,90);
其他 {
如果(getResources()。getConfiguration()。方向== Configuration.ORIENTATION_PORTRAIT){
parameters.set(方向,肖像);
parameters.set(旋转,90);
}
如果(getResources()。getConfiguration()。方向== Configuration.ORIENTATION_LANDSCAPE){
parameters.set(方向,山水);
parameters.set(旋转,90);
}
camera.setParameters(参数);
}
// camera.start preVIEW();
previewing = TRUE;
}
}
拍照
PictureCallback myPictureCallback_JPG =新PictureCallback(){
@覆盖
公共无效onPictureTaken(byte []的为arg0,摄像机ARG1){
// intentar canvia horientacio
位图bitmapPicture = BitmapFactory.de codeByteArray(为arg0,0,arg0.length);
// bitmapPicture。
的OutputStream imageFileOS;
尝试 {
imageFileOS =新的FileOutputStream(的String.Format(/ SD卡/ DCIM / iboo / captura.jpg));
imageFileOS.write(为arg0);
imageFileOS.flush();
imageFileOS.close();
// Missatge恩CAS日capturar L'imatge correctament
Toast.makeText(Principal.this,Imatge Capturada!,
Toast.LENGTH_LONG).show();
MostrarFoto(/ SD卡/ DCIM / iboo / captura.jpg);
}赶上(FileNotFoundException异常E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}
// camera.start preVIEW();
}
};
解决方案
这是我实现的解决方案。它完美。我希望帮助。
PictureCallback myPictureCallback_JPG =新PictureCallback(){
@覆盖
公共无效onPictureTaken(byte []的为arg0,摄像机ARG1){
BitmapFactory.Options选项=新BitmapFactory.Options();
options.inSampleSize = 6;
options.inDither = FALSE; //禁用抖动模式
options.inPurgeable = TRUE; //告诉以GC是是否需要免费
//内存,位图可被清除
options.inInputShareable = TRUE; //哪一种参考值将是
//用于恢复的位图
//当被明确后的数据,
//将在将来被使用
options.inTempStorage =新的字节[32 * 1024];
options.in preferredConfig = Bitmap.Config.RGB_565;
BMAP = BitmapFactory.de codeByteArray(为arg0,0,arg0.length,期权);
//其他设备
如果(bMap.getHeight()&其中; bMap.getWidth()){
定向= 90;
} 其他 {
定向= 0;
}
位图bMapRotate;
如果(取向!= 0){
字模=新的Matrix();
matrix.postRotate(方向);
bMapRotate = Bitmap.createBitmap(BMAP,0,0,bMap.getWidth(),
bMap.getHeight(),矩阵,真正的);
} 其他
bMapRotate = Bitmap.createScaledBitmap(BMAP,bMap.getWidth(),
bMap.getHeight(),TRUE);
FileOutputStream中出;
尝试 {
OUT =新的FileOutputStream(
的String.Format(/ SD卡/ DCIM /测试/ screen.jpg));
bMapRotate.com preSS(Bitmap.Com pressFormat.JPEG,90,出);
如果(bMapRotate!= NULL){
bMapRotate.recycle();
bMapRotate = NULL;
}
}赶上(FileNotFoundException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
camera.start preVIEW();
MostrarFoto(imageInSD);
编辑= prefs.edit();
editor.putString(PathSeleccio,imageInSD);
editor.commit();
}
};
With the following code shows a preview of the camera vertically and it's works.. BUT!! I get a photo in landscape! :(
How I can build it vertically? I've the preview view in vertical, but I can't save the picture vertically.
greetings and thanks, Fran
ONCLICK
public void onClick(View arg0) {
camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG);
}
PREVIEW
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (previewing) {
camera.stopPreview();
previewing = false;
}
if (camera != null) {
/*
* camera.setPreviewDisplay(surfaceHolder); camera.startPreview();
* previewing = true;
*/
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(width, height);
camera.setParameters(parameters);
// Condicions per utilitzar la orientacio adecuada segons el sdk
if (Integer.parseInt(Build.VERSION.SDK) >= 8)
setDisplayOrientation(camera, 90);
else {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
parameters.set("orientation", "portrait");
parameters.set("rotation", 90);
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
parameters.set("orientation", "landscape");
parameters.set("rotation", 90);
}
camera.setParameters(parameters);
}
// camera.startPreview();
previewing = true;
}
}
TAKE PHOTO
PictureCallback myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// intentar canvia horientacio
Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
//bitmapPicture.
OutputStream imageFileOS;
try {
imageFileOS = new FileOutputStream(String.format("/sdcard/DCIM/iboo/captura.jpg"));
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
// Missatge en cas de capturar l'imatge correctament
Toast.makeText(Principal.this, "Imatge Capturada!",
Toast.LENGTH_LONG).show();
MostrarFoto("/sdcard/DCIM/iboo/captura.jpg");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// camera.startPreview();
}
};
解决方案
It is the solution I implemented. It works perfectly. I hope that helps.
PictureCallback myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 6;
options.inDither = false; // Disable Dithering mode
options.inPurgeable = true; // Tell to gc that whether it needs free
// memory, the Bitmap can be cleared
options.inInputShareable = true; // Which kind of reference will be
// used to recover the Bitmap
// data after being clear, when
// it will be used in the future
options.inTempStorage = new byte[32 * 1024];
options.inPreferredConfig = Bitmap.Config.RGB_565;
bMap = BitmapFactory.decodeByteArray(arg0, 0, arg0.length, options);
// others devices
if(bMap.getHeight() < bMap.getWidth()){
orientation = 90;
} else {
orientation = 0;
}
Bitmap bMapRotate;
if (orientation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(),
bMap.getHeight(), matrix, true);
} else
bMapRotate = Bitmap.createScaledBitmap(bMap, bMap.getWidth(),
bMap.getHeight(), true);
FileOutputStream out;
try {
out = new FileOutputStream(
String.format("/sdcard/DCIM/test/screen.jpg"));
bMapRotate.compress(Bitmap.CompressFormat.JPEG, 90, out);
if (bMapRotate != null) {
bMapRotate.recycle();
bMapRotate = null;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
camera.startPreview();
MostrarFoto(imageInSD);
editor = prefs.edit();
editor.putString("PathSeleccio", imageInSD);
editor.commit();
}
};
这篇关于拍照与Android的问题(垂直相机|人像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文