我尝试了许多代码,并查看了 Android 开发人员,但无法使其工作。我希望搜索栏调整我的位图图像亮度
问问题
10693 次
3 回答
8
并在搜索栏进度更改上执行如下所示
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);
}
});
于 2012-07-26T06:00:45.970 回答
1
检查在增加/减少图像亮度中给出的示例
int brightness;
SeekBar seekBarBrightness=(SeekBar)findViewById(R.id.seekBar1);
seekBarBrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
Bitmap newBitMap = doBrightness(bitMap,progress);
imageView.setImageBitmap(newBitMap);
}
});
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;
}
于 2014-02-06T08:55:44.590 回答
1
使用这个例子
SeekBar sb_value = (SeekBar) findViewById(R.id.sb_value);
final ImageView im_brightness = (ImageView) findViewById(R.id.im_brightness);
sb_value.setProgress(125);
sb_value.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
im_brightness.setColorFilter(setBrightness(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
设置亮度方法:
public static PorterDuffColorFilter setBrightness(int progress) {
if (progress >= 100)
{
int value = (int) (progress-100) * 255 / 100;
return new PorterDuffColorFilter(Color.argb(value, 255, 255, 255), PorterDuff.Mode.SRC_OVER);
}
else
{
int value = (int) (100-progress) * 255 / 100;
return new PorterDuffColorFilter(Color.argb(value, 0, 0, 0), PorterDuff.Mode.SRC_ATOP);
}
}
于 2017-05-22T11:18:56.053 回答