我正在做一个项目,我想设置显示的屏幕的对比度,但不是保存的图像。我正在研究相机的效果。我找到了以下参数:
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”的东西,它是否只适用于保存的图像但不能显示屏幕?
答案 0 :(得分: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);
}
简单地说就是private Camera.Parameters p;
和相机是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);
}
});
这将适用于Bitmap,但您可以修改它以使用您想要使用的任何内容!