Skip to content

Commit

Permalink
Tweaked the color data when tapping on the image and updated how the …
Browse files Browse the repository at this point in the history
…cropping works with the camera and gallery.
  • Loading branch information
Robert Montefusco committed Aug 10, 2016
1 parent 7743f41 commit 00362be
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions app/src/main/java/cs371m/chromavision/MainMenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MainMenuActivity extends AppCompatActivity {
private static final int REQUEST_CODE_PERMISSION = 3;
private File storageDir;

private Uri mCameraImageUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -211,10 +213,14 @@ public void takeAPicture(View view) {

Log.d(TAG, "takeAPicture: " + photoUri.toString());

CropImage.activity(photoUri).setGuidelines(CropImageView.Guidelines.ON).start(this);
mCameraImageUri = photoUri;

//CropImage.activity(photoUri).setGuidelines(CropImageView.Guidelines.ON).start(this);

intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, CAMERA_REQUEST_CODE);


}
}

Expand All @@ -235,7 +241,11 @@ public void pickFromGallery(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);

System.out.println("choosing");

startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST_CODE);

}

// public void pickFromGallery(View view) {
Expand Down Expand Up @@ -269,6 +279,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
Bitmap scale = BitmapFactory.decodeStream(cameraInput);

System.out.println(croppedImage);

File delete = new File(croppedImage.toString());
if (delete.exists())
System.out.println("it exists!!!");
delete.delete();

scale = resizeImageToScreen(scale);

OutputStream fOut = null;
Expand Down Expand Up @@ -321,8 +338,14 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
// Check which request we're responding to
if (requestCode == CAMERA_REQUEST_CODE) {
//galleryAddPic();
System.out.println("Inside CAMERA_REQUEST_CODE");

} else if (requestCode == GALLERY_REQUEST_CODE) {
System.out.println(mCameraImageUri);

CropImage.activity(mCameraImageUri).setGuidelines(CropImageView.Guidelines.ON).start(this);

}
else if (requestCode == GALLERY_REQUEST_CODE) {
System.out.println("Inside GALLERY_REQUEST_CODE");

// Get the image from data
Expand All @@ -332,14 +355,16 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
}

System.out.println("selectedImage URI: " + selectedImage);
if (selectedImage != null) {
System.out.println("selectedImage toString: " + selectedImage.toString());
}

CropImage.activity(selectedImage).setGuidelines(CropImageView.Guidelines.ON).start(this);



InputStream galleryInput = null;
if (selectedImage != null) {
galleryInput = getContentResolver().openInputStream(selectedImage);
}

Bitmap scale = BitmapFactory.decodeStream(galleryInput);

scale = resizeImageToScreen(scale);
Expand All @@ -364,7 +389,7 @@ else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
resultIntent.putExtra("pictureUri", fileUri);
resultIntent.putExtra("width", scale.getWidth());
resultIntent.putExtra("height", scale.getHeight());
startActivityForResult(resultIntent, GALLERY_REQUEST_CODE);
//startActivityForResult(resultIntent, GALLERY_REQUEST_CODE);
}
else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
Expand Down
78 changes: 45 additions & 33 deletions app/src/main/java/cs371m/chromavision/ResultActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand Down Expand Up @@ -90,30 +91,32 @@ public boolean onTouch(View view, MotionEvent motionEvent){

if (motionEvent.getAction() == MotionEvent.ACTION_DOWN || motionEvent.getAction() == MotionEvent.ACTION_MOVE){

int x = (int)motionEvent.getX();
int y = (int)motionEvent.getY();

bitmap = mImageView.getDrawingCache();
if((int)motionEvent.getY()<0||(int)motionEvent.getX()<0){
if(y < 0 || x < 0 || y > bitmap.getHeight() || x > bitmap.getWidth()) {




}
else {
if(motionEvent.getY()>bitmap.getHeight()){


}
else {
int pixel = bitmap.getPixel((int) motionEvent.getX(), (int) motionEvent.getY());
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
//System.out.println();

TextView textstuff = (TextView) findViewById(R.id.clickPixel);
textstuff.setBackgroundColor(Color.rgb(redValue, greenValue, blueValue));
System.out.println((int) motionEvent.getX() + " , " + (int) motionEvent.getY());
System.out.println("red =" + redValue + "blue = " + blueValue + "green = " + greenValue);
}
int pixel = bitmap.getPixel(x, y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
//System.out.println();

TextView clickPixelBackground = (TextView) findViewById(R.id.clickPixel);
TextView clickPixelLocation = (TextView) findViewById(R.id.clickPixelText);
LinearLayout border = (LinearLayout) findViewById(R.id.clickPixelBorder);
border.setBackgroundColor(Color.BLACK);
clickPixelBackground.setBackgroundColor(Color.rgb(redValue, greenValue, blueValue));
System.out.println(x + " , " + y);
System.out.println("red =" + redValue + "blue = " + blueValue + "green = " + greenValue);
String loc = "(" + x + ", " + y + "): ";
clickPixelLocation.setText(loc);
}
}
return true;
Expand Down Expand Up @@ -363,7 +366,7 @@ private void determineColors(Bitmap image, String[][] colors) {
image.getPixels(pixels, 0, width, 0, 0, width, height);


int[][] result = new int[height][width];
//int[][] result = new int[height][width];

for (int pixel=0, row=0, col=0; pixel<pixels.length; pixel++) {
int c = pixels[pixel];
Expand All @@ -374,8 +377,8 @@ private void determineColors(Bitmap image, String[][] colors) {
//colors[row][col] = colorDistanceEnum(c).toString();
colors[row][col] = hsbEnum(hsv).toString();

int index = COLORS.valueOf(colors[row][col]).ordinal();
result[row][col] = COLOR_LIST[index];
//int index = COLORS.valueOf(colors[row][col]).ordinal();
//result[row][col] = COLOR_LIST[index];

col++;
if (col == width) {
Expand Down Expand Up @@ -435,7 +438,7 @@ else if ((hsb[1] < 0.20 && hsb[2] >= 0.80) || (deg >= 0.3 && deg < 0.6 && hsb[1]
colorCount[COLORS.valueOf("WHITE").ordinal()]++;
return COLORS.valueOf("WHITE");
}
else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.66) || ((deg < 64 || deg >= 180) && hsb[1] < 0.15)) {
else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.75) || (hsb[1] < 0.4 && hsb[2] < 0.2) || ((deg < 64 || deg >= 180) && hsb[1] < 0.15)) {
// Grey
colorCount[COLORS.valueOf("GREY").ordinal()]++;
return COLORS.valueOf("GREY");
Expand All @@ -448,29 +451,34 @@ else if ((hsb[1] < 0.15 && hsb[2] >= 0.1 && hsb[2] < 0.66) || ((deg < 64 || deg
colorCount[COLORS.valueOf("PINK").ordinal()]++;
return COLORS.valueOf("PINK");
}
else if (hsb[1] >= 0.8 || (deg >= 0 && hsb[1] >= 0.5)) {
else /*if (hsb[1] >= 0.8 || (deg >= 0 && hsb[1] >= 0.5))*/ {
// Red
colorCount[COLORS.valueOf("RED").ordinal()]++;
return COLORS.valueOf("RED");
}
else {
// Dark Red
colorCount[COLORS.valueOf("DARK_RED").ordinal()]++;
return COLORS.valueOf("DARK_RED");
}
// else {
// // Dark Red
// colorCount[COLORS.valueOf("DARK_RED").ordinal()]++;
// return COLORS.valueOf("DARK_RED");
// }
}
else if (deg >= 11 && deg < 45) {
if ((hsb[1] >= 0.8 && hsb[2] >= 0.60)) {
if ((hsb[1] >= 0.8 || hsb[1] > 0.5 && hsb[2] > 0.7 || hsb[2] > 0.85 /*&& hsb[2] >= 0.60*/)) {
// Orange
colorCount[COLORS.valueOf("ORANGE").ordinal()]++;
return COLORS.valueOf("ORANGE");
}
else if ((hsb[2] >= 0.75)) {
// Light Orange
colorCount[COLORS.valueOf("LIGHT_ORANGE").ordinal()]++;
return COLORS.valueOf("LIGHT_ORANGE");
}
// else if ((hsb[2] >= 0.75)) {
// // Light Orange
// colorCount[COLORS.valueOf("LIGHT_ORANGE").ordinal()]++;
// return COLORS.valueOf("LIGHT_ORANGE");
// }
else {
if (hsb[1] < 0.4 && hsb[2] < 0.9) {
// Grey
colorCount[COLORS.valueOf("GREY").ordinal()]++;
return COLORS.valueOf("GREY");
}
// Brown
colorCount[COLORS.valueOf("BROWN").ordinal()]++;
return COLORS.valueOf("BROWN");
Expand All @@ -485,6 +493,10 @@ else if (deg >= 45 && deg < 70) {
colorCount[COLORS.valueOf("BLUE").ordinal()]++;
return COLORS.valueOf("BLUE");
}
else if (hsb[1] < 0.3 && hsb[2] < 0.85) {
colorCount[COLORS.valueOf("GREY").ordinal()]++;
return COLORS.valueOf("GREY");
}
else {
// Yellow
colorCount[COLORS.valueOf("YELLOW").ordinal()]++;
Expand Down
34 changes: 21 additions & 13 deletions app/src/main/res/layout/activity_result.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
android:orientation="horizontal" >

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:textSize="25sp"
android:text="Test Color Data"
android:layout_weight=".5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:id="@+id/clickPixel"
/>
android:gravity="right"
android:layout_weight="0.5"
android:id="@+id/clickPixelText"
android:textIsSelectable="false" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:id="@+id/clickPixelBorder"
android:layout_weight="0.5">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25sp"
android:id="@+id/clickPixel" />
</LinearLayout>



Expand All @@ -41,7 +49,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4">
android:layout_weight="0.5">

<ScrollView
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-w820dp/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</style>

<style name="NoActionBar"
parent="Theme.AppCompat.NoActionBar">
parent="Theme.AppCompat.Light.NoActionBar">

</style>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</style>

<style name="NoActionBar"
parent="Theme.AppCompat.NoActionBar">
parent="Theme.AppCompat.Light.NoActionBar">

</style>

Expand Down

0 comments on commit 00362be

Please sign in to comment.