A
Android Question
Guest
package com.example.rohit2906.secondapp1;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView image = (ImageView) findViewById(R.id.iv_show);
//a Bitmap that will act as a handle to the image
private Bitmap bmOut;
//an integer array that will store ARGB pixel values
private int[][] rgbValues;
/** Called when the activity is first created. */
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//load the image and use the bmp object to access it
bmOut = BitmapFactory.decodeResource(getResources(), R.drawable.iitmandi);
}
public static Bitmap doGamma(Bitmap src, double red, double green, double blue) {
// create output image
private Bitmap bmOut;
bmOut = BitmapFactory.decodeResource(getResources(), R.drawable.iitmandi);
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
// get image size
int width = src.getWidth();
int height = src.getHeight();
// color information
int A, R, G, B;
int pixel;
// constant value curve
final int MAX_SIZE = 256;
final double MAX_VALUE_DBL = 255.0;
final int MAX_VALUE_INT = 255;
final double REVERSE = 1.0;
// gamma arrays
int[] gammaR = new int[MAX_SIZE];
int[] gammaG = new int[MAX_SIZE];
int[] gammaB = new int[MAX_SIZE];
// setting values for every gamma channels
for(int i = 0; i < MAX_SIZE; ++i) {
gammaR = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / red)) + 0.5));
gammaG = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / green)) + 0.5));
gammaB = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / blue)) + 0.5));
}
// apply gamma table
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);
// look up gamma
R = gammaR[Color.red(pixel)];
G = gammaG[Color.green(pixel)];
B = gammaB[Color.blue(pixel)];
// set new color to output bitmap
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
// return final image
return bmOut;
}
}
I want to apply doGamma class to the image bitmap please help me to correct the code.
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView image = (ImageView) findViewById(R.id.iv_show);
//a Bitmap that will act as a handle to the image
private Bitmap bmOut;
//an integer array that will store ARGB pixel values
private int[][] rgbValues;
/** Called when the activity is first created. */
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//load the image and use the bmp object to access it
bmOut = BitmapFactory.decodeResource(getResources(), R.drawable.iitmandi);
}
public static Bitmap doGamma(Bitmap src, double red, double green, double blue) {
// create output image
private Bitmap bmOut;
bmOut = BitmapFactory.decodeResource(getResources(), R.drawable.iitmandi);
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
// get image size
int width = src.getWidth();
int height = src.getHeight();
// color information
int A, R, G, B;
int pixel;
// constant value curve
final int MAX_SIZE = 256;
final double MAX_VALUE_DBL = 255.0;
final int MAX_VALUE_INT = 255;
final double REVERSE = 1.0;
// gamma arrays
int[] gammaR = new int[MAX_SIZE];
int[] gammaG = new int[MAX_SIZE];
int[] gammaB = new int[MAX_SIZE];
// setting values for every gamma channels
for(int i = 0; i < MAX_SIZE; ++i) {
gammaR = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / red)) + 0.5));
gammaG = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / green)) + 0.5));
gammaB = (int)Math.min(MAX_VALUE_INT,
(int)((MAX_VALUE_DBL * Math.pow(i / MAX_VALUE_DBL, REVERSE / blue)) + 0.5));
}
// apply gamma table
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);
// look up gamma
R = gammaR[Color.red(pixel)];
G = gammaG[Color.green(pixel)];
B = gammaB[Color.blue(pixel)];
// set new color to output bitmap
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
// return final image
return bmOut;
}
}
I want to apply doGamma class to the image bitmap please help me to correct the code.