JavaFX writing bmp image pixel by pixel - java

I have written a class to read the BMP files with all the necessary headers as stated here "http://www.ece.ualberta.ca/~elliott/ee552/studentAppNotes/2003_w/misc/bmp_file_format/bmp_file_format.htm"
The class reads all the necessary headers and for the raw data, it reads them as bytes as shown below -
private byte[] calcBytes(String path) throws IOException {
//Get the path of the file
Path file_path = Paths.get(path);
//Return the byte array of the file
return Files.readAllBytes(file_path);
}
Following this, I convert the bytes(stored as little-endian) values to the decimal equivalent and store them as pixel(RGB) values in an array(size: width*height) as shown below.
private int[][] calcPixels(byte[] bytes){
//Find padding, if divisible by 4
int padding = this.width % 4;
//If not divisible by 4, find the closest next that is divisible
if(padding != 0){
//Find closest bigger padding number divisible by 4
while ((padding % 4) != 0){
padding++;
}
}
//Output Pixel array store the pixel values[R,G,B] format
int[][] output_pixels = new int[((this.width + padding) * this.height)][3];
//Initialize the cols(column) of the pixel data as zero
int col = 0;
//Position to fill the output pixel array in correct index
int pos = 0;
//Iterate through the bytes array
for (int index = 0; index < bytes.length; index += 3){
//Increment the col
col++;
//Bytes to hex
String blue_hex = String.format("%02X", bytes[index]);
String green_hex = String.format("%02X", bytes[index+1]);
String red_hex = String.format("%02X", bytes[index+2]);
//Hex to int/short values
short blue = (short) Integer.parseInt(blue_hex, 16);
short green = (short) Integer.parseInt(green_hex, 16);
short red = (short) Integer.parseInt(red_hex, 16);
//Adding to the main array
output_pixels[pos++] = new int[] {red, green, blue};
//Increment Padding with at last column
if(col == (this.width+padding)/4){
//Skip the bytes since it is the padding
index += padding;
//Denote the end of the row or last column[RGB] as [-1,-1,-1], reset the value of the last stored pixel
output_pixels[pos - 1] = new int[] {(short)-1, (short)-1, (short)-1};
//Row will change now
col = 0;
}
}
return output_pixels;
}
Having generated the pixel array with necessary RGB data. I then use JavaFX to generate the pixel represented by a Rectangle shape class and giving it a when iterating through the pixel data array as generated above.
#Override
public void start(Stage primaryStage) throws Exception{
Button button = new Button("Select Image File");
String path = System.getProperty("user.dir") + "/filePath/image.bmp";
//Reads the BMP file and generate headers, bytes and pixels as shown above
BMP bmp = new BMP(path);
//Initialize the root
Group root = new Group();
int[][] pixelsData = bmp.getPixelsData();
//X (to manipulate the x coordinate of the pixel i.e. rectangle shape class)
double xFactor = 1.0;
double startX = 0.0;
double endX = startX + xFactor;
//Y (to manipulate the x coordinate of the pixel i.e. rectangle shape class)
double yFactor = 0.5;
double startY = 0.0;
double endY = startY + yFactor;
for (int index = 0; index < pixelsData.length; index++){
//Get Colors
int red = pixelsData[index][0];
int green = pixelsData[index][1];
int blue = pixelsData[index][2];
if(red == -1 && green == -1 && blue == -1){
//Start Next Line
startY += yFactor;
endY += yFactor;
startX = 0.0;
endX = startX + xFactor;
continue;
}
else {//keep moving the x coordinate
startX += xFactor;
endX += xFactor;
}
Color color = Color.rgb(red,green,blue);
Rectangle rectangle = new Rectangle(startX,startY,endX,endY);
rectangle.setFill(color);
root.getChildren().add(rectangle);
}
primaryStage.setScene(new Scene(root, 700, 700));
primaryStage.show();
}
Now when I actually generate the image with the code above. The image seems to blur out towards the end of the x-axis and also misses a lot of pixels in on the sides.
Example as shown below:
Original Image
JavaFX Image
I also reversed the iteration of my JavaFX pixel data loop in order to generate the image in the right order but no luck.
If you look closely at the original image and the two JavaFX images, it is evident that the left and right side of the "cat" in the pictures is printed fine but blurs out only because of the co-ordinate in my opinion.
I have spent 2 days trying to figure it out but I am really confused. Can someone please help out with my understanding or point out any mistake I might be committing in my code.

Related

Java geotools how to create coverage grid

How to create grid coverage when each cell is 5M ?
I found this :
GridCoverage2D coverage = reader.read(null);
// direct access
DirectPosition position = new DirectPosition2D(crs, x, y);
double[] sample = (double[]) coverage.evaluate(position); // assume double
// resample with the same array
sample = coverage.evaluate(position, sample);
Source : https://docs.geotools.org/latest/userguide/library/coverage/grid.html
I didn't found a lot of tutorial about how to create grid coverage on geotools...
To create an empty coverage you need to use the GridCoverageFactory and one of the create methods. Since you are not constructing from an existing image you need to provide some memory for your raster to be stored in (this can also hold any initial values you want). For this your choices are a float[][] or a WritableRaster. Finally, you need a Envelope to say where the coverage is and what it's resolution is (otherwise it is just an array of numbers), I favour using a ReferencedEnvelope so that I know what the units are etc, so in the example below I have used EPSG:27700 which is the OSGB national grid so I know that it is in metres and I can define the origin somewhere in the South Downs. By specifying the lower left X and Y coordinates and the upper right X and Y as resolution times the width and height (plus the lower left corner) the maths all works out to make sure that the size of my pixels is resolution.
So keeping it simple for now you could do something like:
float[][] data;
int width = 100;
int height = 200;
data = new float[width][height];
int resolution = 5;
for(int i=0;i<width;i++){
for(int j=0;j<height;j++ ){
data[i][j] = 0.0f;
}
}
GridCoverageFactory gcf = new GridCoverageFactory();
CoordinateReferenceSystem crs = CRS.decode("EPSG:27700");
int llx = 500000;
int lly = 105000;
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(llx, llx + (width * resolution), lly, lly + (height * resolution),
crs);
GridCoverage2D gc = gcf.create("name", data, referencedEnvelope);
If you want more bands in your coverage then you need to use a WriteableRaster as the base for your coverage.
WritableRaster raster2 = RasterFactory.createBandedRaster(java.awt.image.DataBuffer.TYPE_INT, width,
height, 3, null);
for (int i = 0; i < width; i++) {//width...
for (int j = 0; j < height; j++) {
raster2.setSample(i, j, 0, rn.nextInt(200));
raster2.setSample(i, j, 1, rn.nextInt(200));
raster2.setSample(i, j, 2, rn.nextInt(200));
}
}

How to do arithmetic operations on pixels in Java

I have to add some constant value to all pixels in my image - for gray image and colored. But I don't know how can I do that. I read image by BufferedImage, and I'm trying to get 2d array of pixels.
I found something like BufferedImage.getRGB() but it returns weird values (negative and huge). How to add some value to my bufferedimage?
You can use:
byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
To get a byte[] of all pixels in the image and then loop over the byte[] adding your constant to each byte element.
If you want the bytes converted to a 2-dimensional byte[], I found an example that does just that (Get Two Dimensional Pixel Array) .
In summary the code looks like:
private static int[][] convertToArrayLocation(BufferedImage inputImage) {
final byte[] pixels = ((DataBufferByte) inputImage.getRaster().getDataBuffer()).getData(); // get pixel value as single array from buffered Image
final int width = inputImage.getWidth(); //get image width value
final int height = inputImage.getHeight(); //get image height value
int[][] result = new int[height][width]; //Initialize the array with height and width
//this loop allocates pixels value to two dimensional array
for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel++) {
int argb = 0;
argb = (int) pixels[pixel];
if (argb < 0) { //if pixel value is negative, change to positive
argb += 256;
}
result[row][col] = argb;
col++;
if (col == width) {
col = 0;
row++;
}
}
return result; //return the result as two dimensional array
} //!end of method!//
To add a constant value to all pixels, you can use RescaleOp. Your constant will be the offset for each channel. Leave scale at 1.0 and hints may be null.
// Positive offset makes the image brighter, negative values makes it darker
int offset = 100; // ...or whatever your constant value is
BufferedImage brighter = new RescaleOp(1, offset, null)
.filter(image, null);
To change the current image, instead of creating a new one, you may use:
new RescaleOp(1, offset, null)
.filter(image, image);

How to draw an image using ASCII symbols?

I am trying to make ASCII Art from an image, but for some reason the output is always rotated and I went through my code a bunch of times and I simply can not find the mistake. I am guessing it's something to do with imageWidth and imageHeight but it all looks fine to me.
Code can be found on github
Draw an ASCII art from an image
Let's assume that one character occupies an area of 21×8 pixels. So first you have to scale down the original image and get the average color of this area, then get the average brightness of this color, and then convert it to a character.
Original picture:
ASCII picture:
This code reads an image from a file, scales it down to 1/21 of the height and 1/8 of the width, calculates the average colors for the scaled areas, then calculates the average brightness for each color and picks a character of the corresponding density, and then saves these characters to a text file.
Without scaling scH=1 and scW=1, the number of characters is equal to the number of pixels in the original image.
public static void main(String[] args) throws IOException {
// assume that one character occupies an area of 21×8 pixels
char[][] chars = readImage("/tmp/image.jpg", 21, 8);
writeToFile("/tmp/image.txt", chars);
}
static char[][] readImage(String path, int scH, int scW) throws IOException {
BufferedImage image = ImageIO.read(new File(path));
int height = image.getHeight() / scH;
int width = image.getWidth() / scW;
char[][] chars = new char[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
// scaling image and accumulating colors
int colorRGB = 0;
for (int k = 0; k < scH; k++)
for (int p = 0; p < scW; p++)
colorRGB += image.getRGB(j * scW + p, i * scH + k);
// get the average color
Color color = new Color(colorRGB / (scH * scW));
// read the R, G, B values of the color and get the average brightness
int brightness = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
// get a character depending on the brightness value
chars[i][j] = getDensity(brightness);
}
}
return chars;
}
static final String DENSITY =
"#QB#NgWM8RDHdOKq9$6khEPXwmeZaoS2yjufF]}{tx1zv7lciL/\\|?*>r^;:_\"~,'.-`";
static char getDensity(int value) {
// Since we don't have 255 characters, we have to use percentages
int charValue = (int) Math.round(DENSITY.length() / 255.0 * value);
charValue = Math.max(charValue, 0);
charValue = Math.min(charValue, DENSITY.length() - 1);
return DENSITY.charAt(charValue);
}
static void writeToFile(String path, char[][] chars) throws IOException {
FileWriter writer = new FileWriter(path);
for (char[] row : chars) {
String str = String.valueOf(row);
writer.append(str).write("\n");
System.out.println(str);
}
writer.flush();
writer.close();
}
Output:
***************************************
***************************************
*************o/xiz|{,/1ctx*************
************77L*```````*_1{j***********
**********?i```````````````FZ**********
**********l`````````````````7**********
**********x`````````````````L**********
**********m?i`````````````iz1**********
************]x```````````\x{***********
********?1w]c>```````````La{]}r********
******jSF~```````````````````^xv>******
*****l1,```````````````````````*Sj*****
****7t```````````````````````````v7****
***uL`````````````````````````````t]***
See also: Restore an image from an ASCII art with Java • Convert image to ASCII art
Creating character density and brightness maps
You can create your own character density map from any range of characters, and then, since the densities are not evenly distributed, convert it to a brightness map and further call the ceilingEntry and floorEntry methods.
First draw each character as a black-and-white picture using java.awt package and count the number of pixels - you get a density map. Then for each entry from this map, calculate the percentage of brightness on the scale 0-255 - you get a brightness map.
Pictures:
Original picture
ASCII: 0 - 2550x0000 - 0x00FF
Runic:0x16A0 - 0x16FF
Box Drawing:0x2500 - 0x257F
Block Elements:0x2580 - 0x259F
Geometric Shapes:0x25A0 - 0x25FF
Hiragana:0x3040 - 0x309F
Density scales:
Unicode block
Range of characters
Density scale
ASCII
0-255
¶#ØÆMåBNÊßÔR#8Q&mÃ0À$GXZA5ñk2S%±3Fz¢yÝCJf1t7ªLc¿+?(r/¤²!*;"^:,'.`
Runic
0x16A0-0x16FF
ᛥᛤᛞᚥᚸᛰᛖᚻᚣᛄᚤᛒᚢᚱᛱᚷᚫᛪᚧᚬᚠᛏᚨᚰᚩᚮᚪᚳᚽᚿᛊᛁᛵᛍ᛬ᚲᛌ᛫
Box Drawing
0x2500-0x257F
╬╠╫╋║╉╩┣╦╂╳╇╈┠╚┃╃┻╅┳┡┢┹╀╧┱╙┗┞┇┸┋┯┰┖╲╱┎╘━┭┕┍┅╾│┬┉╰╭╸└┆╺┊─╌┄┈╴╶
Block Elements
0x2580-0x259F
█▉▇▓▊▆▅▌▚▞▀▒▐▍▃▖▂░▁▏
Geometric Shapes
0x25A0-0x25FF
◙◘■▩●▦▣◚◛◕▨▧◉▤◐◒▮◍◑▼▪◤▬◗◭◖◈◎◮◊◫▰◄◯□▯▷▫▽◹△◁▸▭◅▵◌▱▹▿◠◃◦◟◞◜
Hiragana
0x3040-0x309F
ぽぼゑぜぬあおゆぎゐはせぢがきぱびほげばゟぁたかぞぷれひずどらさでけぉちごえすゎにづぇとょついこぐうぅぃくっしへゞゝ゚゙
Code:
public static void main(String[] args) {
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 22);
// ASCII characters: 0 - 255
// Runic: 0x16A0 - 0x16FF
// Box Drawing: 0x2500 - 0x257F
// Block Elements: 0x2580 - 0x259F
// Geometric Shapes: 0x25A0 - 0x25FF
// Hiragana: 0x3040 - 0x309F
TreeMap<Integer, List<String>> density = getDensityMap(font,0x25A0,0x25FF,0);
// the map of brightness of pixels [0, 255]
TreeMap<Integer, List<String>> brightness = getBrightnessMap(density);
// output, geometric shapes
for (List<String> value : brightness.values()) System.out.print(value.get(0));
// ◙◘■▩●▦▣◚◛◕▨▧◉▤◐◒▮◍◑▼▪◤▬◗◭◖◈◎◮◊◫▰◄◯□▯▷▫▽◹△◁▸▭◅▵◌▱▹▿◠◃◦◟◞◜
}
/**
* #param density character density map
* #return the pixel brightness map [0, 255],
* based on percentages of character density
*/
static TreeMap<Integer, List<String>> getBrightnessMap(
TreeMap<Integer, List<String>> density) {
int max = density.lastKey(); // maximum density
TreeMap<Integer, List<String>> brightness = new TreeMap<>();
for (Map.Entry<Integer, List<String>> entry : density.entrySet()) {
// pixel brightness, based on the percentage of character density
int key = (int) Math.round(255.0 - entry.getKey() * 255.0 / max);
List<String> value = entry.getValue();
List<String> val = brightness.remove(key);
if (val == null) val = new ArrayList<>();
val.addAll(value);
brightness.put(key, val);
}
return brightness;
}
/**
* #param f font to render text
* #param min character codepoint range, lower bound
* #param max character codepoint range, upper bound
* #param pd padding as a precaution, in most cases 0
* #return the character density map:
* key - density, value - list of characters
*/
static TreeMap<Integer, List<String>> getDensityMap(
Font f, int min, int max, int pd) {
// key - density, value - list of characters
TreeMap<Integer, List<String>> density = new TreeMap<>();
for (int i = min; i <= max; i++) {
// printable characters
if (f.canDisplay(i) && Character.isDefined(i)
&& !Character.isISOControl(i)
&& !Character.isIdentifierIgnorable(i)) {
String str = String.valueOf(Character.toChars(i));
int key = getDensity(str, f, pd);
List<String> list = density.remove(key);
if (list == null) list = new ArrayList<>();
list.add(str);
density.put(key, list);
}
}
return density;
}
/**
* #param text source text to draw
* #param f font to render text
* #param pd padding as a precaution, in most cases 0
* #return the density of the characters in this text
*/
static int getDensity(String text, Font f, int pd) {
FontRenderContext ctx = new FontRenderContext(f.getTransform(), false, false);
Rectangle bounds = f.getStringBounds(text, ctx).getBounds();
int width = bounds.width + pd * 2;
int height = bounds.height + pd * 2;
BufferedImage image =
new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setFont(f);
graphics.drawString(text, pd + bounds.x, pd - bounds.y);
//ImageIO.write(image, "png", new File("text.png"));
int density = 0;
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
if (image.getRGB(j, i) == 0xFFFFFFFF)
density++;
return density;
}
In ImageWriting.java, line 34:
this.writer.append(Density.DENSITY.getDensityFor(this.brightnessValues[j][i]));
I strongly suspect that you are stepping through one coordinate in some for loop with the other loop nested inside. (Not going to chase after code on another site.)
Try swapping the nesting of the for loops or the order of accessing an element by array indices (replacing the [i][j] code fragment with [j][i] or similar according to whatever code you have on another site that I'm not going to chase after).

Find first red pixel and crop picture

I want to find with OpenCV first red pixel and cut rest of picture on right of it.
For this moment I wrote this code, but it work very slow:
int firstRedPixel = mat.Cols();
int len = 0;
for (int x = 0; x < mat.Rows(); x++)
{
for (int y = 0; y < mat.Cols(); y++)
{
double[] rgb = mat.Get(x, y);
double r = rgb[0];
double g = rgb[1];
double b = rgb[2];
if ((r > 175) && (r > 2 * g) && (r > 2 * b))
{
if (len == 3)
{
firstRedPixel = y - len;
break;
}
len++;
}
else
{
len = 0;
}
}
}
Any solutions?
You can:
1) find red pixels (see here)
2) get the bounding box of red pixels
3) crop your image
The code is in C++, but it's only OpenCV functions so it should not be difficult to port to Java:
#include <opencv2\opencv.hpp>
int main()
{
cv::Mat3b img = cv::imread("path/to/img");
// Find red pixels
// https://stackoverflow.com/a/32523532/5008845
cv::Mat3b bgr_inv = ~img;
cv::Mat3b hsv_inv;
cv::cvtColor(bgr_inv, hsv_inv, cv::COLOR_BGR2HSV);
cv::Mat1b red_mask;
inRange(hsv_inv, cv::Scalar(90 - 10, 70, 50), cv::Scalar(90 + 10, 255, 255), red_mask); // Cyan is 90
// Get the rect
std::vector<cv::Point> red_points;
cv::findNonZero(red_mask, red_points);
cv::Rect red_area = cv::boundingRect(red_points);
// Show green rectangle on red area
cv::Mat3b out = img.clone();
cv::rectangle(out, red_area, cv::Scalar(0, 255, 0));
// Define the non red area
cv::Rect not_red_area;
not_red_area.x = 0;
not_red_area.y = 0;
not_red_area.width = red_area.x - 1;
not_red_area.height = img.rows;
// Crop away red area
cv::Mat3b result = img(not_red_area);
return 0;
}
This is not the way to work with computer vision. I know this, because I did it the same way.
One way to achieve your goal would be to use template matching with a red bar that you cut out of your image, and thus locate the red border, and cut it away.
Another would be to transfer to HSV space, filter out red content, and use contour finding to locate a large red structure, as you need it.
There are plenty of ways to do this. Looping yourself over pixel-values rarely is the right approach though, and you won't take advantage of sophisticated vectorisation or algorithms that way.

How to get pixel value of Black and White Image?

I making App in netbeans platform using java Swing and JAI. In this i want to do image processing. I capture .tiff black and white image using X-Ray gun. after that i want to plot histogram of that Black and White image. so, for plot to histogram , first we have to get gray or black and white image pixel value. then we can plot histogram using this pixel value.so, how can i get this pixel value of black and white image?
This should work if you use java.awt.image.BufferedImage.
Since you want to create a histogram, I suppose you will loop through all the pixels. There is the method for returning a single pixel value.
int getRGB(int x, int y)
However, since looping will take place I suppose you'd want to use this one:
int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
When you get the array, use:
int alpha = (pixels[i] >> 24) & 0x000000FF;
int red = (pixels[i] >> 16) & 0x000000FF;
int green = (pixels[i] >>8 ) & 0x000000FF;
int blue = pixels[i] & 0x000000FF;
To extract the channel data. Not sure if the variables can be declared as byte (we are using only one byte of the integer in the array, although byte is signed and different arithmetic takes place - two's complement form), but you can declare them as short.
Then preform some maths on these values, for example:
int average = (red + green + blue) / 3;
This will return the average for the pixel, giving you a point you can use in a simple luminosity histogram.
EDIT:
Regarding histogram creation, I have used this class. It takes the image you want the histogram of as an argument to its setImage(BufferedImage image) method. Use updateHistogram() for array populating. The drawing data is in paintComponent(Graphics g). I must admit, it is sloppy, especially when calculating the offsets, but it can be easily simplified.
Here is the whole class:
class HistogramCtrl extends JComponent
{
BufferedImage m_image;
int[] m_histogramArray = new int[256]; //What drives our histogram
int m_maximumPixels;
public HistogramCtrl(){
m_maximumPixels = 0;
for(short i = 0; i<256; i++){
m_histogramArray[i] = 0;
}
}
void setImage(BufferedImage image){
m_image = image;
updateHistogram();
repaint();
}
void updateHistogram(){
if(m_image == null) return;
int[] pixels = m_image.getRGB(0, 0, m_image.getWidth(), m_image.getHeight(), null, 0, m_image.getWidth());
short currentValue = 0;
int red,green,blue;
for(int i = 0; i<pixels.length; i++){
red = (pixels[i] >> 16) & 0x000000FF;
green = (pixels[i] >>8 ) & 0x000000FF;
blue = pixels[i] & 0x000000FF;
currentValue = (short)((red + green + blue) / 3); //Current value gives the average //Disregard the alpha
assert(currentValue >= 0 && currentValue <= 255); //Something is awfully wrong if this goes off...
m_histogramArray[currentValue] += 1; //Increment the specific value of the array
}
m_maximumPixels = 0; //We need to have their number in order to scale the histogram properly
for(int i = 0; i < m_histogramArray.length;i++){ //Loop through the elements
if(m_histogramArray[i] > m_maximumPixels){ //And find the bigges value
m_maximumPixels = m_histogramArray[i];
}
}
}
protected void paintComponent(Graphics g){
assert(m_maximumPixels != 0);
Rectangle rect = g.getClipBounds();
Color oldColor = g.getColor();
g.setColor(new Color(210,210,210));
g.fillRect((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight());
g.setColor(oldColor);
String zero = "0";
String thff = "255";
final short ctrlWidth = (short)rect.getWidth();
final short ctrlHeight = (short)rect.getHeight();
final short activeWidth = 256;
final short activeHeight = 200;
final short widthSpacing = (short)((ctrlWidth - activeWidth)/2);
final short heightSpacing = (short)((ctrlHeight - activeHeight)/2);
Point startingPoint = new Point();
final int substraction = -1;
startingPoint.x = widthSpacing-substraction;
startingPoint.y = heightSpacing+activeHeight-substraction;
g.drawString(zero,widthSpacing-substraction - 2,heightSpacing+activeHeight-substraction + 15);
g.drawString(thff,widthSpacing+activeWidth-substraction-12,heightSpacing+activeHeight-substraction + 15);
g.drawLine(startingPoint.x, startingPoint.y, widthSpacing+activeWidth-substraction, heightSpacing+activeHeight-substraction);
g.drawLine(startingPoint.x,startingPoint.y,startingPoint.x,heightSpacing-substraction);
double factorHeight = (double)activeHeight / m_maximumPixels; //The height divided by the number of pixels is the factor of multiplication for the other dots
Point usingPoint = new Point(startingPoint.x,startingPoint.y);
usingPoint.x+=2; //I want to move this two points in order to be able to draw the pixels with value 0 a bit away from the limit
Point tempPoint = new Point();
for(short i = 0; i<256; i++){
tempPoint.x = usingPoint.x;
tempPoint.y = (int)((heightSpacing+activeHeight-substraction) - (m_histogramArray[i] * factorHeight));
if((i!=0 && (i % 20 == 0)) || i == 255){
oldColor = g.getColor();
g.setColor(oldColor.brighter());
//Draw horizontal ruler sections
tempPoint.x = widthSpacing + i;
tempPoint.y = heightSpacing+activeHeight-substraction+4;
g.drawLine(tempPoint.x,tempPoint.y,widthSpacing + i,heightSpacing+activeHeight-substraction-4);
if(i <= 200){
//Draw vertical ruler sections
tempPoint.x = widthSpacing - substraction - 3;
tempPoint.y = heightSpacing+activeHeight-substraction-i;
g.drawLine(tempPoint.x,tempPoint.y,widthSpacing - substraction + 4, heightSpacing+activeHeight-substraction-i);
}
tempPoint.x = usingPoint.x;
tempPoint.y = usingPoint.y;
g.setColor(oldColor);
}
g.drawLine(usingPoint.x, usingPoint.y, tempPoint.x, tempPoint.y);
usingPoint.x++; //Set this to the next point
}
}
}

Categories