How to increase brightness of the button? - android

Hi I have one application in that when am try to touch any button that one should be more brighter compared to remaining all the button.
I have tried one code it is working fine .but,it is taking too much for displaying.
Can any one tell me any other way I can do it?
if (themeClick.equals("6")) {/*cool*/
mTick1.setVisibility(View.VISIBLE);
mTick2.setVisibility(View.VISIBLE);
mTick3.setVisibility(View.VISIBLE);
mTick4.setVisibility(View.VISIBLE);
mTick5.setVisibility(View.VISIBLE);
mTick6.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.cool),-80));
mTick1.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.classic),-0));
mTick2.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.casual1),-0));
mTick3.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.natural),-0));
mTick4.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.smart),-0));
mTick5.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.meeting),-0));
mTick6.setVisibility(View.VISIBLE);
}
public Bitmap SetBrightness(Bitmap src, int value) {
// original 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;
}

Related

image brightness taking too much time for click

Hi In my application am displaying some themes .In that theme when am pressing any image that image background will turn to give little bit more brighter compared to remaining all the themes.
Now, My issue is while pressing the image it is taking too much work on main thread.How to do while pressing the image fast touch should happens.
Can any one please help me to resolve this issue.
sample.java:
mTick1.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.classic),-80));
mTick2.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.casual1),-0));
mTick3.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.natural),-0));
mTick4.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.smart),-0));
mTick5.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.meeting),-0));
mTick6.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.cool),-0));
mTick1.setVisibility(View.VISIBLE);
mTick2.setVisibility(View.VISIBLE);
mTick3.setVisibility(View.VISIBLE);
mTick4.setVisibility(View.VISIBLE);
mTick5.setVisibility(View.VISIBLE);
mTick6.setVisibility(View.VISIBLE);
mTick6.setVisibility(View.VISIBLE);
Brightness method:
public Bitmap SetBrightness(Bitmap src, int value) {
// original 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;
}

What may cause the unexpected behavior with bitmap filter?

I have a problem with a function to adjust bitmap contrast.
This function is being set by 2 seekbars, when I change the first value on a seekbar everything is fine, but when value is from 0 to 99 on a second seekbar nothing is changing. Only if the value is 100 the bitmap is changing and gets the contrast effect.
public Bitmap applyRGBFilters2(Bitmap src, int valueContrast, int valueBrightness){
int width = src.getWidth();
int height = src.getHeight();
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
int A, R, G, B;
int pixel;
double contrast = Math.pow((100 + valueContrast) / 100, 2);
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
R = (int)(((((R / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(R < 0) { R = 0; }
else if(R > 255) { R = 255; }
G = Color.green(pixel);
G = (int)(((((G / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(G < 0) { G = 0; }
else if(G > 255) { G = 255; }
B = Color.blue(pixel);
B = (int)(((((B / 255.0) - 0.5) * contrast) + 0.5) * 255.0);
if(B < 0) { B = 0; }
else if(B > 255) { B = 255; }
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
Bitmap bmOut2 = Bitmap.createBitmap(bmOut);
Bitmap bmOut3 = Bitmap.createBitmap(width, height, bmOut2.getConfig());
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = bmOut3.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
R += valueBrightness;
if(R > 255) { R = 255; }
else if(R < 0) { R = 0; }
G += valueBrightness;
if(G > 255) { G = 255; }
else if(G < 0) { G = 0; }
B += valueBrightness;
if(B > 255) { B = 255; }
else if(B < 0) { B = 0; }
bmOut3.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut3;
}
Do you see any wrong things here?

How can we enhance apply Brightness Effect with custom filter?

I am trying to add custom filter and add brightness and contrast, but it takes to much time.
How can i decrease these times?
Can we use other way or add filter over filter?
//main class
private ImageView imgMain;
imgMain = (ImageView) findViewById(R.id.effect_main);
imgMain.setColorFilter(filterClass.setFilter(2));
Bitmap bitmap = ((BitmapDrawable)imgMain.getDrawable()).getBitmap();
bitmap =imgFilter.applyBrightnessEffect(bitmap , 150);
imgMain.setImageBitmap(bitmap);
for custom filter
//filter methords
public ColorMatrixColorFilter catNightFilter() {
float[] matrix = {
89, 61, -5, 0, 0, //red
77, 67, 24, 0, 0, //green
-57, -13, 81, 0, 0, //blue
0, 0, 0, 0, 0 //alpha
};
ColorMatrix cm = new ColorMatrix(matrix);``
return new ColorMatrixColorFilter(cm);
}
This Brightness code takes to much time it convert each pixel.
// scan through all pixels
//britness methord
public Bitmap applyBrightnessEffect(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;
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;
}

How to programatically apply effects on imageview image in android?

i want to apply various effects on image view image.this image is already sent from main activity.i have the code for effects but don't know the method how to apply it on button click.kindly guide me.
public class PhotoEffect extends Activity implements OnClickListener {
ImageView camphoto;
Bitmap bmp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photoeffect);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Bundle extras=getIntent().getExtras();
//b=(Bitmap)extras.get("img");
byte[] byteArray=extras.getByteArray("img");
bmp=BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
camphoto=(ImageView)findViewById(R.id.camimage);
camphoto.setImageBitmap(bmp);
/*if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}*/
}
#Override
public void onClick(View v)
{
Bitmap bitmap = ((BitmapDrawable)camphoto.getDrawable()).getBitmap();
switch (v.getId())
{
case R.id.btnsepia:
//Bitmap bitmap = ((BitmapDrawable)camphoto.getDrawable()).getBitmap();
camphoto.setImageBitmap(createSepiaToningEffect(bitmap, 2, .5, .6, .59));
break;
case R.id.btnhighlight:
camphoto.setImageBitmap(doHighlightImage(bitmap));
break;
}
}
You must define the createSepiaToningEffect function like this returning a Bitmap after processing.
public static Bitmap createSepiaToningEffect(Bitmap src, int depth, double red, double green, double blue) {
int width = src.getWidth();
int height = src.getHeight();
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
final double GS_RED = 0.3;
final double GS_GREEN = 0.59;
final double GS_BLUE = 0.11;
int A, R, G, B;
int pixel;
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
B = G = R = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);
// apply intensity level for sepid-toning on each channel
R += (depth * red);
if(R > 255) { R = 255; }
G += (depth * green);
if(G > 255) { G = 255; }
B += (depth * blue);
if(B > 255) { B = 255; }
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut;
}

How adjust brightness of bitmap in gradient format in android?

I have seen so many links and posts of to adjust birightness of bitmap in android, but i want to adjust brightness with gradient, like adjust brightness of only center of the bitmap. Anybody have any idea how to do this ?
You can generate a bitmap and draw a gradient:
How to draw a smooth/dithered gradient on a canvas in Android
Then use each pixel from gradient bitmap and get the brightness and pass it to the function that adjust brightness.
look here Formula to determine brightness of RGB color
public Bitmap SetBrightness(Bitmap src, Bitmap gradient) {
// original 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);
int gradientPixel = gradient.getPixel(x, y);
int value = getLuminance(gradientPixel);
// 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;
}
public int getLuminance(int pixel) {
int A, R, G, B;
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
}

Categories

Resources