diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 2adf3f2..1510c24 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,10 @@
-
+
+
+
+
@@ -15,8 +18,8 @@
-
-
+
+
@@ -27,15 +30,12 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
@@ -50,6 +50,9 @@
+
+
+
+
+
+
@@ -89,37 +95,27 @@
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
@@ -201,21 +198,24 @@
+
+
-
-
+
+
-
+
+
@@ -226,9 +226,7 @@
-
-
@@ -257,12 +255,9 @@
-
-
-
-
-
-
+
+
+
@@ -282,20 +277,44 @@
-
-
-
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/collage.jpg b/collage.jpg
new file mode 100644
index 0000000..a881445
Binary files /dev/null and b/collage.jpg differ
diff --git a/src/com/company/Main.java b/src/com/company/Main.java
index ea909ee..d0d1fd0 100644
--- a/src/com/company/Main.java
+++ b/src/com/company/Main.java
@@ -8,22 +8,25 @@ public class Main {
public static void main(String[] args) throws IOException {
- File file = new File("bear.jpg"); // I have bear.jpg in my working directory
+ File file = new File("C:\\Users\\Elliot\\Desktop\\bear.jpeg");
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
- int rows = 20; //You should decide the values for rows and cols variables
+ int rows = 20;
int cols = 30;
int chunks = rows * cols;
int chunkWidth = image.getWidth() / cols; // determines the chunk width and height
int chunkHeight = image.getHeight() / rows;
int count = 0;
- chunk imgs[] = new chunk[chunks];
+ chunk[] imgs = new chunk[chunks];
for (int x = 0; x < rows; x++) {
for (int y = 0; y < cols; y++) {
//Initialize the image array with image chunks
- imgs[count].setImg(new BufferedImage(chunkWidth, chunkHeight, image.getType()));
+ BufferedImage tempimg = new BufferedImage(chunkWidth, chunkHeight, image.getType());
+ imgs[count] = new chunk(tempimg);
+ imgs[count].average();
+
// draws the image chunk
Graphics2D gr = imgs[count++].getImg().createGraphics();
@@ -31,14 +34,7 @@ public class Main {
gr.dispose();
}
}
-
-
- //writing mini images into image files
- for (int i = 0; i < imgs.length; i++) {
- ImageIO.write(imgs[i].getImg(), "jpg", new File("img" + i + ".jpg"));
- }
-
- ImageIO.write(image, "jpg", new File("collage.jpg"));
+ ImageIO.write(imgs[2].getImg(), "jpg", new File("collage.jpg"));
}
}
diff --git a/src/com/company/chunk.java b/src/com/company/chunk.java
index 185263a..66f7da7 100644
--- a/src/com/company/chunk.java
+++ b/src/com/company/chunk.java
@@ -1,7 +1,8 @@
package com.company;
+import java.awt.*;
import java.awt.image.BufferedImage;
-
+import javax.imageio.ImageIO;
public class chunk {
@@ -18,21 +19,35 @@ public class chunk {
this.img = img;
}
public int[] average(){
- int r = 0, g = 0, b = 0, x= 0, y = 0, clr;
+ int r = 0, g = 0, b = 0, a = 0, x= 0, y = 0;
+
+ for(; y < this.img.getHeight(); y++){
+ for(; x < this.img.getWidth(); x++){
+
+ //get pixel value
+ int p = this.img.getRGB(x,y);
+
+ //get alpha
+ a = (p>>24) & 0xff;
+
+ //get red
+ r = (p>>16) & 0xff;
+
+ //get green
+ g = (p>>8) & 0xff;
+
+ //get blue
+ a = p & 0xff;
- for(; x < this.img.getWidth(); x++){
- for(; x < this.img .getHeight(); x++){
- clr = this.img.getRGB(x, y);
- r += (clr & 0x00ff0000) >> 16;
- g += (clr & 0x0000ff00) >> 8;
- b += clr & 0x000000ff;
}
}
r /= x*y;
g /= x*y;
b /= x*y;
+ a /= x*y;
+ System.out.println(r + " , " + g + " , " + b + " , " + a);
return new int[]{r,g,b};
}
}