-6

我正在做一个项目,我想设置显示的屏幕对比度,但不是保存的图像。我正在研究相机的效果。我发现了以下参数:

String   EFFECT_AQUA

String   EFFECT_BLACKBOARD

String   EFFECT_MONO

String   EFFECT_NEGATIVE

String   EFFECT_NONE

String   EFFECT_POSTERIZE

String   EFFECT_SEPIA

String   EFFECT_SOLARIZE

String   EFFECT_WHITEBOARD

我想知道如何使用它们以及它们之间的区别。另外,你能举个例子来告诉我如何使用它们。

顺便说一下,我也看了下 EffectFactory。我发现了类似“String EFFECT_CONTRAST”的东西,它只适用于保存的图像而不是屏幕显示吗?

4

1 回答 1

3

首先,在布局中添加这些按钮。

<Button
    android:id="@+id/captureFront"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:onClick="onCaptureClick"
    android:text="Take Photo" />

<Button
    android:id="@+id/sepia"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:onClick="onSepiaClick"
    android:text="Sepia"
    android:visibility="visible" />

<Button
    android:id="@+id/none"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:onClick="onNoneClick"
    android:text="None" />

<Button
    android:id="@+id/solarize"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="onSolarizeClick"
    android:text="Solarize" />

<Button
    android:id="@+id/mono"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:onClick="onMonoClick"
    android:text="Mono" />

<Button
    android:id="@+id/negative"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:onClick="onNegativeClick"
    android:text="Negative" />

那么这里是每个的 onClick 方法

    public void onNoneClick(View view){
    p = camera.getParameters();
    p.setColorEffect("none");
    camera.setParameters(p);
}

public void onMonoClick(View view){
    p = camera.getParameters();
    p.setColorEffect("mono");
    camera.setParameters(p);
}

public void onSepiaClick(View view){
    p = camera.getParameters();
    p.setColorEffect("sepia");
    camera.setParameters(p);
}
public void onSolarizeClick(View view){
    p = camera.getParameters();
    p.setColorEffect("solarize");
    camera.setParameters(p);
}
public void onNegativeClick(View view){
    p = camera.getParameters();
    p.setColorEffect("negative");
    camera.setParameters(p);
}

只是 pprivate Camera.Parameters p; 和 camera 是private Camera camera;

编辑

public static Bitmap doBrightness(Bitmap src, int value) {
    // image size
    int width = src.getWidth();
    int height = src.getHeight();
    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    // color information
    int A, R, G, B;
    int pixel;

    // scan through all pixels
    for(int x = 0; x < width; ++x) {
        for(int y = 0; y < height; ++y) {
            // get pixel color
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);

            // increase/decrease each channel
            R += value;
            if(R > 255) { R = 255; }
            else if(R < 0) { R = 0; }

            G += value;
            if(G > 255) { G = 255; }
            else if(G < 0) { G = 0; }

            B += value;
            if(B > 255) { B = 255; }
            else if(B < 0) { B = 0; }

            // apply new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}



  int brightness;
 SeekBar seekbarbrightness=(SeekBar)findViewById(R.id.seekBar1);
 seekbarbrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

         @Override
         public void onStopTrackingTouch(SeekBar arg0) {
          // TODO Auto-generated method stub

         }

         @Override
         public void onStartTrackingTouch(SeekBar arg0) {
          // TODO Auto-generated method stub

         }

         @Override
         public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

             // TODO Auto-generated method stub

             brightness=progress;
             Bitmap bitmap=doBrightness(originalbitmap,brightness);
             imageView.setImageBitmap(bitmap);
         }
        });

好吧,这将适用于位图,但您可以修改它以使用您想使用的任何东西!

于 2013-04-13T08:44:41.663 回答