欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android的零星基础点(多媒体)之一 博客分类: Android android 

程序员文章站 2024-02-13 18:06:34
...
照相机应用相关内容:
1.颜色效果:
Camera.Parameters parameters = camera.getParameters();
List<String> colorEffects = parameters.getSupportedColorEffects();
Iterator<String> cei = colorEffects.iterator();
while (cei.hasNext()) {
   String currentEffect = cei.next();
   Log.v("SNAPSHOT","Checking " + currentEffect);
   if (currentEffect.equals(Camera.Parameters.EFFECT_SOLARIZE)) {
        Log.v("SNAPSHOT","Using SOLARIZE");
        parameters.setColorEffect(Camera.Parameters.EFFECT_SOLARIZE);
        break;
   }
}
Log.v("SNAPSHOT","Using Effect: " + parameters.getColorEffect());
camera.setParameters(parameters);


这部份代码引用自 《Pro android media》。

camera.getParameters();方法获取本机照相机的支持参数,
parameters.getSupportedColorEffects();这里是获取照相机所支持的颜色效果。

整段大意是,首先获取了支持参数、颜色效果,然后把遍历出颜色效果看是否存在所需的颜色效果,如果存在就设置成该效果。

一些效果参数:
引用

EFFECT_NONE
EFFECT_MONO
EFFECT_NEGATIVE
EFFECT_SOLARIZE
EFFECT_SEPIA
EFFECT_POSTERIZE
EFFECT_WHITEBOARD
EFFECT_BLACKBOARD
EFFECT_AQUA


2.显示大小:

……
public static final int LARGEST_WIDTH = 200;
public static final int LARGEST_HEIGHT= 200;
……

public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try {
         camera.setPreviewDisplay(holder);
         Camera.Parameters parameters = camera.getParameters();
         int bestWidth = 0;
         int bestHeight = 0;
         List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
        if (previewSizes.size() > 1){
             Iterator<Camera.Size> cei = previewSizes.iterator();
             while (cei.hasNext()){
                   Camera.Size aSize = cei.next();
                   Log.v("SNAPSHOT","Checking " + aSize.width + " x " + aSize.height);
                   if (aSize.width > bestWidth && aSize.width <= LARGEST_WIDTH
&& aSize.height > bestHeight && aSize.height <= LARGEST_HEIGHT) {
                  // So far it is the biggest without going over the screen dimensions
                   bestWidth = aSize.width;
                   bestHeight = aSize.height;
               }
         }
         if (bestHeight != 0 && bestWidth != 0) {
             Log.v("SNAPSHOT", "Using " + bestWidth + " x " + bestHeight);
             parameters.setPreviewSize(bestWidth, bestHeight);
             cameraView.setLayoutParams(new LinearLayout.LayoutParams( bestWidth,
             bestHeight));
         }
     }
      camera.setParameters(parameters);
      //After we set the parameters, all that remains is to close out the    surfaceCreated method. 
    } catch (IOException exception) {
    camera.release();
   }
}



parameters.getSupportedPreviewSizes();获取照相机支持的预览大小。

cameraView.setLayoutParams(new LinearLayout.LayoutParams( bestWidth,bestHeight));
通知SurfaceView对象,camaraView 来显示那样的大小。如没有这样做,SurfaceView将不会改变显示大小,来自照相机的预览图片将会或扭曲的或非常低质量。



整段代码的大意是:在所技持的预览大小内,自定义预览大小。
相关标签: android