├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── image1.png
│ │ │ │ ├── image3.png
│ │ │ │ ├── minions.png
│ │ │ │ ├── simpsons.jpg
│ │ │ │ └── ironmancartoon.jpg
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── activity_frame.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hackathon
│ │ │ │ └── picfix
│ │ │ │ ├── data
│ │ │ │ ├── SketchType.java
│ │ │ │ └── Constants.java
│ │ │ │ ├── transform
│ │ │ │ ├── RotationEffect.java
│ │ │ │ └── FlipImage.java
│ │ │ │ ├── utils
│ │ │ │ ├── BlurBuilder.java
│ │ │ │ └── BitmapBuilder.java
│ │ │ │ ├── filters
│ │ │ │ ├── Shading.java
│ │ │ │ ├── Blur.java
│ │ │ │ ├── WaterMark.java
│ │ │ │ ├── Saturation.java
│ │ │ │ ├── Flea.java
│ │ │ │ ├── BlackFilter.java
│ │ │ │ ├── Hue.java
│ │ │ │ ├── Snow.java
│ │ │ │ ├── TintImage.java
│ │ │ │ ├── Brightness.java
│ │ │ │ └── Sketch.java
│ │ │ │ ├── adapter
│ │ │ │ └── FrameSelectorAdaptor.java
│ │ │ │ ├── interfaces
│ │ │ │ ├── CustomFrameInterface.java
│ │ │ │ └── PicFixViewInterface.java
│ │ │ │ ├── activity
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── FrameActivity.java
│ │ │ │ └── widgets
│ │ │ │ └── PicFixImageView.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── hackathon
│ │ └── picfix
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/drawable/image1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/drawable/image3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/minions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/drawable/minions.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/simpsons.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/drawable/simpsons.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ironmancartoon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/drawable/ironmancartoon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shilu-stha/PicFix/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PicFix
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #80000000
4 | #FF000000
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hackathon/picfix/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/data/SketchType.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.data;
2 |
3 | /**
4 | * Sketch types which ranges from 3-5.
5 | *
6 | * @author Shilu
7 | * @date 7/4/15
8 | */
9 | public enum SketchType {
10 |
11 | NEGATIVE(3),
12 | PENCIL_SKETCH(4),
13 | COLOR_PENCIL_SKETCH(5);
14 |
15 |
16 | private final int type;
17 |
18 | SketchType(int type) {
19 | this.type = type;
20 | }
21 |
22 | public int getType() {
23 | return type;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.hackathon.picfix"
9 | minSdkVersion 17
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:22.2.0'
25 | }
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | .idea/
30 | .gradle/
31 | *.iml
32 | *.iws
33 | *.ipr
34 | *~
35 | *.swp
36 |
37 | /*/local.properties
38 | /*/out
39 |
40 | # Built application files
41 | /*/build/
42 | /*/production
43 | .gradle
44 | /local.properties
45 | /.idea/workspace.xml
46 | /.idea/libraries
47 | /build
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/leapfrog/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PicFix
2 | Android Image Editing Library
3 |
4 | PicFix is an android image editing library with simple, easy support for image manipulation.
5 |
6 | # Features
7 | Effects
8 | - Brightness
9 | - Blur Effect
10 | - Flea Effect
11 | - Hue
12 | - Black Filter
13 | - Saturation
14 | - Snow Effect
15 | - Shade Image
16 | - Sketch Image
17 | - Tint Image
18 |
19 | Transforms
20 | - Flip
21 | - Rotate
22 | - Resize
23 |
24 | # Benefits
25 | - Hassle free coding
26 | - Increase efficiency
27 | - Easy image editing
28 |
29 | # Development Configuration:
30 |
31 | Android SDK Tools: 24.3.3
32 | Android SDK Platform-tools: 23 rc3
33 | Android SDK Build-tools: 23 rc2
34 | Android Compatibility: API 17 and above
35 | View Mode: Portrait Mode
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/data/Constants.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.data;
2 |
3 | /**
4 | * Constant values used by library
5 | *
6 | * @date 7/3/15
7 | */
8 | public class Constants {
9 |
10 | public static final int COLOR_MIN = 0x00;
11 | public static final int COLOR_MAX = 0xFF;
12 |
13 |
14 | public static final double PI = 3.14159d;
15 | public static final double FULL_CIRCLE_DEGREE = 360d;
16 | public static final double HALF_CIRCLE_DEGREE = 180d;
17 | public static final double RANGE = 256d;
18 |
19 | public static final boolean mIsError = false;
20 |
21 | // image flip type definition
22 | public static final int FLIP_VERTICAL = 1;
23 | public static final int FLIP_HORIZONTAL = 2;
24 |
25 | // blurr builder definitions
26 | private static final float BLUR_RADIUS = 7.5f;
27 | public static final float BITMAP_SCALE = 0.6f;
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
16 |
17 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/transform/RotationEffect.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.transform;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Matrix;
5 |
6 | /**
7 | * Provides rotated effect to the bitmap
8 | *
9 | * @date 7/3/15
10 | */
11 | public class RotationEffect {
12 |
13 | /**
14 | * Rotates the given bitmap image with the rotation degree supplied.
15 | * Changes the matrix of the bitmap for rotation.
16 | *
17 | * @param image supplied bitmap
18 | * @param rotationDegree rotation degree can be 0-360
19 | * @return rotated bitmap
20 | */
21 | public static Bitmap getRotatedBitmap(Bitmap image, float rotationDegree) {
22 |
23 | // create new matrix
24 | Matrix matrix = new Matrix();
25 | // setup rotation degree
26 | matrix.postRotate(rotationDegree);
27 |
28 | // return new bitmap rotated using matrix
29 |
30 | return Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), matrix, true);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/transform/FlipImage.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.transform;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Matrix;
5 |
6 | import com.hackathon.picfix.data.Constants;
7 |
8 | /**
9 | * Flip the bitmap
10 | *
11 | * @date 7/3/15
12 | */
13 | public class FlipImage {
14 |
15 | /**
16 | * This method flips the supplied bitmap according to the flip type supplied changing the {@link Matrix} of the image
17 | *
18 | * @param definedBitmap supplied bitmap to be change
19 | * @param flipType constant to rotate the image with. It could be Constants.FLIP_VERTICAL and Constants.FLIP_HORIZONTAL
20 | * @return flipped bitmap
21 | */
22 | public static Bitmap getFlippedImage(Bitmap definedBitmap, int flipType) {
23 |
24 | // create new matrix for transformation
25 | Matrix matrix = new Matrix();
26 |
27 | // if vertical
28 | if (flipType == Constants.FLIP_VERTICAL) {
29 | // y = y * -1
30 | matrix.preScale(1.0f, -1.0f);
31 | }
32 |
33 | // if horizontal
34 | else if (flipType == Constants.FLIP_HORIZONTAL) {
35 | // x = x * -1
36 | matrix.preScale(-1.0f, 1.0f);
37 | // unknown type
38 | } else {
39 | return null;
40 | }
41 |
42 | return Bitmap.createBitmap(definedBitmap, 0, 0, definedBitmap.getWidth(), definedBitmap.getHeight(), matrix, true);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/utils/BlurBuilder.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.renderscript.Allocation;
6 | import android.renderscript.Element;
7 | import android.renderscript.RenderScript;
8 | import android.renderscript.ScriptIntrinsicBlur;
9 |
10 | /**
11 | * Build blur image
12 | *
13 | * @author Manas
14 | * @date 7/3/15
15 | */
16 | public class BlurBuilder {
17 | private static final float BITMAP_SCALE = 0.6f;
18 | private static final float BLUR_RADIUS = 7.5f;
19 |
20 | public static Bitmap blur(Context context, Bitmap image, float radius) {
21 | int width = Math.round(image.getWidth() * BITMAP_SCALE);
22 | int height = Math.round(image.getHeight() * BITMAP_SCALE);
23 |
24 | Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
25 | Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
26 |
27 | RenderScript rs = RenderScript.create(context);
28 | ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
29 | Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
30 | Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
31 | theIntrinsic.setRadius(radius);
32 | theIntrinsic.setInput(tmpIn);
33 | theIntrinsic.forEach(tmpOut);
34 | tmpOut.copyTo(outputBitmap);
35 |
36 | return outputBitmap;
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Shading.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Provides shading effect of supplied color over bitmap
7 | *
8 | * @date 7/3/15
9 | */
10 | public class Shading {
11 |
12 | /**
13 | * Updates each pixel of the bitmap with the supplied shading color.
14 | *
15 | * @param definedBitmap supplied bitmap
16 | * @param shadingColor hex code of shading color
17 | * @return shaded bitmap
18 | */
19 | public static Bitmap getShadingEffect(Bitmap definedBitmap, int shadingColor) {
20 | // get image size
21 | int width = definedBitmap.getWidth();
22 | int height = definedBitmap.getHeight();
23 | int[] pixels = new int[width * height];
24 | // get pixel array from source
25 | definedBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
26 |
27 | int index = 0;
28 | // iteration through pixels
29 | for (int y = 0; y < height; ++y) {
30 | for (int x = 0; x < width; ++x) {
31 | // get current index in 2D-matrix
32 | index = y * width + x;
33 | // AND
34 | pixels[index] &= shadingColor;
35 | }
36 | }
37 | // output bitmap
38 | Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
39 | bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
40 | return bmOut;
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/adapter/FrameSelectorAdaptor.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.Gallery;
8 | import android.widget.ImageView;
9 |
10 | import com.hackathon.picfix.utils.BitmapBuilder;
11 |
12 | /**
13 | * Adapter to set frames
14 | *
15 | * @author shilushrestha
16 | * @date 7/3/15
17 | */
18 | public class FrameSelectorAdaptor extends BaseAdapter {
19 | private Context mContext;
20 | private Integer[] mFrames;
21 |
22 |
23 | public FrameSelectorAdaptor(Context context, Integer[] frames) {
24 | mContext = context;
25 | mFrames = frames;
26 | }
27 |
28 | public int getCount() {
29 | return mFrames.length;
30 | }
31 |
32 | public Object getItem(int position) {
33 | return position;
34 | }
35 |
36 | public long getItemId(int position) {
37 | return position;
38 | }
39 |
40 | public View getView(int index, View view, ViewGroup viewGroup) {
41 | ImageView i = new ImageView(mContext);
42 | i.setImageBitmap(BitmapBuilder.decodeSampledBitmapFromResource(
43 | mContext.getResources(), mFrames[index], 100,
44 | 100));
45 | i.setLayoutParams(new Gallery.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
46 | i.setScaleType(ImageView.ScaleType.FIT_XY);
47 |
48 | return i;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Blur.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.renderscript.Allocation;
6 | import android.renderscript.Element;
7 | import android.renderscript.RenderScript;
8 | import android.renderscript.ScriptIntrinsicBlur;
9 |
10 | import com.hackathon.picfix.data.Constants;
11 |
12 | /**
13 | * Set Blur effect
14 | *
15 | * @author Manas
16 | * @date 7/3/15
17 | */
18 | public class Blur {
19 |
20 | /**
21 | * @param context
22 | * @param bitmap supplied bitmap
23 | * @param radius supplied radius of blur effect
24 | * @return blurred bitmap
25 | */
26 | public static Bitmap blur(Context context, Bitmap bitmap, float radius) {
27 | int width = Math.round(bitmap.getWidth() * Constants.BITMAP_SCALE);
28 | int height = Math.round(bitmap.getHeight() * Constants.BITMAP_SCALE);
29 |
30 | Bitmap inputBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);
31 | Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
32 |
33 | RenderScript rs = RenderScript.create(context);
34 | ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
35 | Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
36 | Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
37 | theIntrinsic.setRadius(radius);
38 | theIntrinsic.setInput(tmpIn);
39 | theIntrinsic.forEach(tmpOut);
40 | tmpOut.copyTo(outputBitmap);
41 |
42 | return outputBitmap;
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/WaterMark.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Point;
7 |
8 | /**
9 | * Set watermark to the bitmap
10 | *
11 | * @date 7/3/15
12 | */
13 | public class WaterMark {
14 |
15 | /**
16 | * @param definedBitmap supplied bitmap
17 | * @param watermark string to applied as watermark
18 | * @param location location where watermark is to be set
19 | * @param color color of the string to be set as watermark
20 | * @param alpha alpha of the color to be applied
21 | * @param size size of the string
22 | * @param underline true if underline needed else false
23 | * @return watermarked bitmap
24 | */
25 | public static Bitmap getWaterMarked(Bitmap definedBitmap, String watermark, Point location, int color, int alpha, int size, boolean underline) {
26 |
27 | int w = definedBitmap.getWidth();
28 | int h = definedBitmap.getHeight();
29 | Bitmap waterMarkedBitmap = Bitmap.createBitmap(w, h, definedBitmap.getConfig());
30 |
31 | Canvas canvas = new Canvas(waterMarkedBitmap);
32 | canvas.drawBitmap(definedBitmap, 0, 0, null);
33 |
34 | Paint paint = new Paint();
35 | paint.setColor(color);
36 | paint.setAlpha(alpha);
37 | paint.setTextSize(size);
38 | paint.setAntiAlias(true);
39 | paint.setUnderlineText(underline);
40 | canvas.drawText(watermark, location.x, location.y, paint);
41 |
42 | return waterMarkedBitmap;
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/interfaces/CustomFrameInterface.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.interfaces;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 |
6 | import com.hackathon.picfix.widgets.PicFixImageView;
7 |
8 | /**
9 | * Created by shilu shrestha on 7/3/15.
10 | * all the methods used to set frame are defined here.
11 | */
12 | public interface CustomFrameInterface {
13 |
14 | /**
15 | * Set resource location for custom frames to be used in the application
16 | *
17 | * @param frames - resource id list
18 | */
19 | void setFrames(Integer[] frames);
20 |
21 | /**
22 | * Return the frames used by the application
23 | *
24 | * @return the frame id list
25 | */
26 | Integer[] getFrames();
27 |
28 | /**
29 | * Set frames as overlay on top of the required image view.
30 | *
31 | * @param context - application context
32 | * @param frameImageView - {@link android.widget.ImageView} which contain selected frame
33 | * @param selectedImageView - {@link PicFixImageView} which contains bitmap
34 | */
35 | void createFrameOverlay(Context context, PicFixImageView frameImageView, PicFixImageView selectedImageView);
36 |
37 | /**
38 | * Set selected frame from adapter. Change the frames on top of ImageView accordingly.
39 | *
40 | * @param position - position of selected frame
41 | */
42 | void setSelectedFrame(int position);
43 |
44 | /**
45 | * Returns the final framed bitmap of the image.
46 | *
47 | * @param selectedImageView - {@link PicFixImageView} which contains bitmap to set frame
48 | * @param position - position of selected frame
49 | */
50 | Bitmap getFramedBitmap(PicFixImageView selectedImageView, int position);
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Saturation.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | /**
7 | * Provide saturation effect to the bitmap
8 | *
9 | * @date 7/3/15
10 | */
11 | public class Saturation {
12 |
13 | /**
14 | * Change HSV(Hue-Saturation Value) of the bitmap by the saturation level.
15 | *
16 | * @param definedBitmap supplied bitmap
17 | * @param saturationLevel integer level
18 | * @return filtered bitmap
19 | */
20 | public static Bitmap getSaturatedFilter(Bitmap definedBitmap, int saturationLevel) {
21 | // get image size
22 | int width = definedBitmap.getWidth();
23 | int height = definedBitmap.getHeight();
24 | int[] pixels = new int[width * height];
25 | float[] HSV = new float[3];
26 | // get pixel array from source
27 | definedBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
28 |
29 | int index;
30 | // iteration through pixels
31 | for (int y = 0; y < height; ++y) {
32 | for (int x = 0; x < width; ++x) {
33 | // get current index in 2D-matrix
34 | index = y * width + x;
35 | // convert to HSV
36 | Color.colorToHSV(pixels[index], HSV);
37 | // increase Saturation level
38 | HSV[1] *= saturationLevel;
39 | HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
40 | // take color back
41 | pixels[index] |= Color.HSVToColor(HSV);
42 | }
43 | }
44 | // output bitmap
45 | Bitmap saturatedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
46 | saturatedBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
47 |
48 | return saturatedBitmap;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.graphics.Point;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.hackathon.picfix.widgets.PicFixImageView;
11 | import com.hackathon.picfix.R;
12 | import com.hackathon.picfix.data.SketchType;
13 |
14 |
15 | public class MainActivity extends Activity {
16 |
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | Point location=new Point();
24 | location.set(2000, 2000);
25 |
26 | PicFixImageView asd = (PicFixImageView) findViewById(R.id.ivTest);
27 |
28 | Button btn = (Button) findViewById(R.id.btnFrames);
29 | btn.setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | Intent intent = new Intent();
33 | intent.setClass(getApplicationContext(), FrameActivity.class);
34 | startActivity(intent);
35 | }
36 | });
37 |
38 | // asd.setRotationTo(67);
39 | // asd.setBlur(25);
40 | // asd.setBrightness(80);
41 | // asd.setShading(Color.parseColor("#00aa32"));
42 | // asd.applyBlackFilter();/
43 | // asd.applyHueFilter(50);
44 | // asd.setColorFilter(asd.applyHue(50));
45 | // asd.sketch(SketchType.PENCIL_SKETCH.getType(),250);
46 | // asd.adjustHue(50);
47 | // asd.applySaturationFilter(80);
48 | asd.applySnowEffect();
49 | // asd.applyFleaEffect();
50 | // asd.setTintImage(20);
51 | // asd.flipImage(Constants.FLIP_VERTICAL);
52 | // asd.sketch();
53 | // asd.setWaterMark("Hackathon", location, Color.BLACK, 10, 30, false);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Flea.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | import com.hackathon.picfix.data.Constants;
7 |
8 | import java.util.Random;
9 |
10 | /**
11 | * Set Flea Effect in the given bitmap
12 | *
13 | * @date 7/3/15
14 | */
15 | public class Flea {
16 |
17 | /**
18 | * This method takes each pixel in the bitmap and
19 | * then change them according to the random value generated from COLOR_MAX and COLOR_MIN from {@link Constants}
20 | *
21 | * @param definedBitmap supplied bitmap
22 | * @return flea effect added bitmap
23 | */
24 |
25 | public static Bitmap getFleaEffectBitmap(Bitmap definedBitmap) {
26 | // get image size
27 | int width = definedBitmap.getWidth();
28 | int height = definedBitmap.getHeight();
29 | int[] pixels = new int[width * height];
30 |
31 | // get pixel array from source
32 | definedBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
33 |
34 | // a random object
35 | Random random = new Random();
36 |
37 | int index = 0;
38 |
39 | // iteration through pixels
40 | for (int y = 0; y < height; ++y) {
41 | for (int x = 0; x < width; ++x) {
42 | // get current index in 2D-matrix
43 | index = y * width + x;
44 | // get random color
45 | int randColor = Color.rgb(random.nextInt(Constants.COLOR_MAX),
46 | random.nextInt(Constants.COLOR_MAX), random.nextInt(Constants.COLOR_MAX));
47 | // OR
48 | pixels[index] |= randColor;
49 | }
50 | }
51 |
52 | // output bitmap
53 | Bitmap fleaEffectBitmap = Bitmap.createBitmap(width, height, definedBitmap.getConfig());
54 | fleaEffectBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
55 |
56 | return fleaEffectBitmap;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/BlackFilter.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | import com.hackathon.picfix.data.Constants;
7 |
8 | import java.util.Random;
9 |
10 | /**
11 | * Apply black filter to provided bitmap
12 | *
13 | * @date 7/3/15
14 | */
15 | public class BlackFilter {
16 |
17 | /**
18 | *
19 | * @param definedBitmap
20 | * @return
21 | */
22 | public static Bitmap getBlackFilteredImage(Bitmap definedBitmap) {
23 |
24 | // get image size
25 | int width = definedBitmap.getWidth();
26 | int height = definedBitmap.getHeight();
27 | int[] pixels = new int[width * height];
28 |
29 | // get pixel array from source
30 | definedBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
31 |
32 | // random object
33 | Random random = new Random();
34 |
35 | int R, G, B, index = 0, threshold = 0;
36 |
37 | // iteration through pixels
38 | for (int y = 0; y < height; ++y) {
39 |
40 | for (int x = 0; x < width; ++x) {
41 | // get current index in 2D-matrix
42 | index = y * width + x;
43 | // get color
44 | R = Color.red(pixels[index]);
45 | G = Color.green(pixels[index]);
46 | B = Color.blue(pixels[index]);
47 | // generate threshold
48 | threshold = random.nextInt(Constants.COLOR_MAX);
49 | if (R < threshold && G < threshold && B < threshold) {
50 | pixels[index] = Color.rgb(Constants.COLOR_MIN, Constants.COLOR_MIN, Constants.COLOR_MIN);
51 | }
52 | }
53 | }
54 | // output bitmap
55 | Bitmap blackFilteredBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
56 | blackFilteredBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
57 |
58 | return blackFilteredBitmap;
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_frame.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
16 |
17 |
22 |
23 |
32 |
33 |
42 |
43 |
44 |
45 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Hue.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 | import android.graphics.ColorFilter;
6 | import android.graphics.ColorMatrix;
7 | import android.graphics.ColorMatrixColorFilter;
8 |
9 | /**
10 | * Provides Hue Filter effect to the bitmap created
11 | *
12 | * @date 7/3/15
13 | */
14 | public class Hue {
15 |
16 | /**
17 | * Creates a HUE ajustment ColorFilter
18 | *
19 | * @param value degrees to shift the hue.
20 | * @return
21 | */
22 | public static ColorFilter adjustHue(float value) {
23 | ColorMatrix cm = new ColorMatrix();
24 |
25 | adjustHue(cm, value);
26 |
27 | return new ColorMatrixColorFilter(cm);
28 | }
29 |
30 | /**
31 | * @param cm
32 | * @param value
33 | */
34 | public static void adjustHue(ColorMatrix cm, float value) {
35 | value = cleanValue(value, 180f) / 180f * (float) Math.PI;
36 | if (value == 0) {
37 | return;
38 | }
39 | float cosVal = (float) Math.cos(value);
40 | float sinVal = (float) Math.sin(value);
41 | float lumR = 0.213f;
42 | float lumG = 0.715f;
43 | float lumB = 0.072f;
44 | float[] mat = new float[]
45 | {
46 | lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0,
47 | lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0,
48 | lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0,
49 | 0f, 0f, 0f, 1f, 0f,
50 | 0f, 0f, 0f, 0f, 1f};
51 | cm.postConcat(new ColorMatrix(mat));
52 | }
53 |
54 | protected static float cleanValue(float p_val, float p_limit) {
55 | return Math.min(p_limit, Math.max(-p_limit, p_val));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Snow.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | import com.hackathon.picfix.data.Constants;
7 |
8 | import java.util.Random;
9 |
10 | /**
11 | * Sets Snow Effect in Image view
12 | *
13 | * @date 7/3/15
14 | */
15 | public class Snow {
16 |
17 | /**
18 | * This method applies Snow effect to the supplied bitmap calculating RGB value
19 | * according to the COLOR_MAX and COLOR_MIN from {@link Constants}
20 | *
21 | * @param definedBitmap supplied bitmap to be change
22 | * @return snow effect added bitmap
23 | */
24 |
25 | public static Bitmap getSnowEffectBitmap(Bitmap definedBitmap) {
26 | // get image size
27 | int width = definedBitmap.getWidth();
28 | int height = definedBitmap.getHeight();
29 | int[] pixels = new int[width * height];
30 | // get pixel array from source
31 | definedBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
32 | // random object
33 | Random random = new Random();
34 |
35 | int R;
36 | int G;
37 | int B;
38 | int index;
39 | int threshold;
40 | // iteration through pixels
41 | for (int y = 0; y < height; ++y) {
42 | for (int x = 0; x < width; ++x) {
43 | // get current index in 2D-matrix
44 | index = y * width + x;
45 | // get color
46 | R = Color.red(pixels[index]);
47 | G = Color.green(pixels[index]);
48 | B = Color.blue(pixels[index]);
49 | // generate threshold
50 | threshold = random.nextInt(Constants.COLOR_MAX);
51 | if (R > threshold && G > threshold && B > threshold) {
52 | pixels[index] = Color.rgb(Constants.COLOR_MAX, Constants.COLOR_MAX, Constants.COLOR_MAX);
53 | }
54 | }
55 | }
56 | // output bitmap
57 | Bitmap snowEffectBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
58 | snowEffectBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
59 |
60 | return snowEffectBitmap;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/TintImage.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.hackathon.picfix.data.Constants;
6 |
7 | /**
8 | * Provide tint effect to bitmap
9 | *
10 | * @date 7/3/15
11 | */
12 | public class TintImage {
13 |
14 | /**
15 | * This method takes the RGB value of each pixel in the bitmap and then change them according to the tint degree supplied.
16 | *
17 | * @param definedBitmap supplied bitmap
18 | * @param tintDegree degree of tint value to be set
19 | * @return tint added bitmap
20 | */
21 | public static Bitmap getTintImage(Bitmap definedBitmap, int tintDegree) {
22 | int width = definedBitmap.getWidth();
23 | int height = definedBitmap.getHeight();
24 |
25 | int[] pix = new int[width * height];
26 | definedBitmap.getPixels(pix, 0, width, 0, 0, width, height);
27 |
28 | int RY, GY, BY, RYY, GYY, BYY, R, G, B, Y;
29 | double angle = (Constants.PI * (double) tintDegree) / Constants.HALF_CIRCLE_DEGREE;
30 |
31 | int S = (int) (Constants.RANGE * Math.sin(angle));
32 | int C = (int) (Constants.RANGE * Math.cos(angle));
33 |
34 | for (int y = 0; y < height; y++)
35 | for (int x = 0; x < width; x++) {
36 | int index = y * width + x;
37 | int r = (pix[index] >> 16) & 0xff;
38 | int g = (pix[index] >> 8) & 0xff;
39 | int b = pix[index] & 0xff;
40 | RY = (70 * r - 59 * g - 11 * b) / 100;
41 | BY = (-30 * r - 59 * g + 89 * b) / 100;
42 | Y = (30 * r + 59 * g + 11 * b) / 100;
43 | RYY = (S * BY + C * RY) / 256;
44 | BYY = (C * BY - S * RY) / 256;
45 | GYY = (-51 * RYY - 19 * BYY) / 100;
46 | R = Y + RYY;
47 | R = (R < 0) ? 0 : ((R > 255) ? 255 : R);
48 | G = Y + GYY;
49 | G = (G < 0) ? 0 : ((G > 255) ? 255 : G);
50 | B = Y + BYY;
51 | B = (B < 0) ? 0 : ((B > 255) ? 255 : B);
52 | pix[index] = 0xff000000 | (R << 16) | (G << 8) | B;
53 | }
54 |
55 | Bitmap tintedBitmap = Bitmap.createBitmap(width, height, definedBitmap.getConfig());
56 | tintedBitmap.setPixels(pix, 0, width, 0, 0, width, height);
57 |
58 | return tintedBitmap;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Brightness.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | /**
7 | * Set Brightness to the given bitmap with supplied amount of brightness
8 | *
9 | * @date 7/3/15
10 | */
11 | public class Brightness {
12 |
13 | /**
14 | * This method takes the RGB value of each pixel in the bitmap and then change them according to the brightness value supplied.
15 | *
16 | * @param definedBitmap supplied bitmap
17 | * @param brightnessValue brightness value to be set
18 | * @return brightness added bitmap
19 | */
20 | public static Bitmap getBrightnessEffect(Bitmap definedBitmap, int brightnessValue) {
21 |
22 | // image size
23 | int width = definedBitmap.getWidth();
24 | int height = definedBitmap.getHeight();
25 |
26 | // create output bitmap
27 | Bitmap brightnessAddedBitmap = Bitmap.createBitmap(width, height, definedBitmap.getConfig());
28 |
29 | // color information
30 | int A, R, G, B;
31 | int pixel;
32 |
33 | // scan through all pixels
34 | for (int x = 0; x < width; ++x) {
35 | for (int y = 0; y < height; ++y) {
36 |
37 | // get pixel color
38 | pixel = definedBitmap.getPixel(x, y);
39 | A = Color.alpha(pixel);
40 | R = Color.red(pixel);
41 | G = Color.green(pixel);
42 | B = Color.blue(pixel);
43 |
44 | // increase/decrease each channel
45 | R += brightnessValue;
46 | if (R > 255) {
47 | R = 255;
48 | } else if (R < 0) {
49 | R = 0;
50 | }
51 |
52 | G += brightnessValue;
53 | if (G > 255) {
54 | G = 255;
55 | } else if (G < 0) {
56 | G = 0;
57 | }
58 |
59 | B += brightnessValue;
60 | if (B > 255) {
61 | B = 255;
62 | } else if (B < 0) {
63 | B = 0;
64 | }
65 |
66 | // apply new pixel color to output bitmap
67 | brightnessAddedBitmap.setPixel(x, y, Color.argb(A, R, G, B));
68 | }
69 | }
70 | return brightnessAddedBitmap;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/filters/Sketch.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.filters;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Color;
5 |
6 | import com.hackathon.picfix.data.SketchType;
7 |
8 | /**
9 | * Convert bitmap into sketch image
10 | *
11 | * @author Manas
12 | * @date 7/4/2015
13 | */
14 | public class Sketch {
15 |
16 | /**
17 | * Set the type of sketch you want to create
18 | *
19 | * @param bitmap supplied bitmap
20 | * @return sketched bitmap
21 | */
22 | public static final Bitmap changeToSketch(Bitmap bitmap) {
23 | return changeToSketch(bitmap, SketchType.COLOR_PENCIL_SKETCH.getType(), 250);
24 | }
25 |
26 |
27 | /**
28 | * Multiply each RGB value of the supplied bitmap to sketch type selected
29 | * and create a final value with added threshold.
30 | *
31 | * @param bitmap supplied bitmap
32 | * @param type {@link SketchType} value for sketch
33 | * @param threshold point to implement the sketch effect
34 | * @return sketched bitmap
35 | */
36 | public static Bitmap changeToSketch(Bitmap bitmap, int type, int threshold) {
37 | int width = bitmap.getWidth();
38 | int height = bitmap.getHeight();
39 | Bitmap result = Bitmap.createBitmap(width, height, bitmap.getConfig());
40 |
41 | int A, R, G, B;
42 | int sumR, sumG, sumB;
43 | int[][] pixels = new int[3][3];
44 | for (int y = 0; y < height - 2; ++y) {
45 | for (int x = 0; x < width - 2; ++x) {
46 | // get pixel matrix
47 | for (int i = 0; i < 3; ++i) {
48 | for (int j = 0; j < 3; ++j) {
49 | pixels[i][j] = bitmap.getPixel(x + i, y + j);
50 | }
51 | }
52 | // get alpha of center pixel
53 | A = Color.alpha(pixels[1][1]);
54 | // init color sum
55 | sumR = sumG = sumB = 0;
56 | sumR = (type * Color.red(pixels[1][1])) - Color.red(pixels[0][0]) - Color.red(pixels[0][2]) - Color.red(pixels[2][0]) - Color.red(pixels[2][2]);
57 | sumG = (type * Color.green(pixels[1][1])) - Color.green(pixels[0][0]) - Color.green(pixels[0][2]) - Color.green(pixels[2][0]) - Color.green(pixels[2][2]);
58 | sumB = (type * Color.blue(pixels[1][1])) - Color.blue(pixels[0][0]) - Color.blue(pixels[0][2]) - Color.blue(pixels[2][0]) - Color.blue(pixels[2][2]);
59 | // get final Red
60 | R = sumR + threshold;
61 | if (R < 0) {
62 | R = 0;
63 | } else if (R > 255) {
64 | R = 255;
65 | }
66 | // get final Green
67 | G = sumG + threshold;
68 | if (G < 0) {
69 | G = 0;
70 | } else if (G > 255) {
71 | G = 255;
72 | }
73 | // get final Blue
74 | B = sumB + threshold;
75 | if (B < 0) {
76 | B = 0;
77 | } else if (B > 255) {
78 | B = 255;
79 | }
80 |
81 | result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
82 | }
83 | }
84 | return result;
85 | }
86 |
87 |
88 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/activity/FrameActivity.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.activity;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.os.Bundle;
6 | import android.os.Environment;
7 | import android.view.View;
8 | import android.widget.AdapterView;
9 | import android.widget.Button;
10 | import android.widget.Gallery;
11 |
12 | import com.hackathon.picfix.widgets.PicFixImageView;
13 | import com.hackathon.picfix.R;
14 | import com.hackathon.picfix.adapter.FrameSelectorAdaptor;
15 |
16 | import java.io.ByteArrayOutputStream;
17 | import java.io.File;
18 | import java.io.FileNotFoundException;
19 | import java.io.FileOutputStream;
20 | import java.io.IOException;
21 |
22 |
23 | public class FrameActivity extends Activity {
24 |
25 | private final Integer[] mImageIds = {R.drawable.image1, R.drawable.image3};
26 | private int mPosition;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_frame);
32 |
33 | final PicFixImageView imageView = (PicFixImageView) findViewById(R.id.overlayselected);
34 | final PicFixImageView imageViewFrame = (PicFixImageView) findViewById(R.id.overlayFrame);
35 | imageView.setFrames(mImageIds);
36 | imageView.createFrameOverlay(this, imageViewFrame, imageView);
37 |
38 | Gallery gallery = (Gallery) findViewById(R.id.gallery);
39 | gallery.setSpacing(50);
40 | gallery.setAdapter(new FrameSelectorAdaptor(this, mImageIds));
41 | gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
42 |
43 | @Override
44 | public void onItemClick(AdapterView> parent, View view,
45 | int position, long id) {
46 | mPosition = position;
47 | imageView.setSelectedFrame(position);
48 |
49 |
50 | }
51 | });
52 |
53 | Button btn = (Button) findViewById(R.id.btnDone);
54 | btn.setOnClickListener(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View v) {
57 |
58 | Bitmap bitmap = imageView.getFramedBitmap(imageView, mPosition);
59 |
60 | //todo used newly created image path to show it later.
61 | String path = setFrameSave ("sample", "framed", bitmap);
62 | }
63 | });
64 | }
65 |
66 | /**
67 | * Save the bitmap to required location with supplied filename.
68 | *
69 | * @param fileName - name of the file
70 | * @param fileLocation - file location
71 | * @param bitmap - bitmap to store
72 | * @return - file path
73 | */
74 | private String setFrameSave(String fileName, String fileLocation, Bitmap bitmap) {
75 | File file = new File(Environment
76 | .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), fileLocation);
77 | if (!file.exists()) {
78 | file.mkdir();
79 | }
80 | File bitmapFile = new File(file, fileName + System.currentTimeMillis() + ".jpeg");
81 | FileOutputStream out;
82 | try {
83 | ByteArrayOutputStream bytesOfImage = new ByteArrayOutputStream();
84 |
85 | out = new FileOutputStream(bitmapFile);
86 | out.write(bytesOfImage.toByteArray());
87 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytesOfImage);
88 | // out.close();
89 | } catch (FileNotFoundException e) {
90 | e.printStackTrace();
91 | } catch (IOException e) {
92 | e.printStackTrace();
93 | }
94 |
95 | return bitmapFile.getAbsolutePath();
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/interfaces/PicFixViewInterface.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.interfaces;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.ColorFilter;
5 | import android.graphics.Point;
6 |
7 | /**
8 | *Interface to handle all the image editor function
9 | */
10 | public interface PicFixViewInterface {
11 |
12 | /**
13 | * Enable rotation for the bitmap
14 | *
15 | * @param rotationDegree - Degree to rotate image, range 0-360
16 | */
17 | void setRotationTo(float rotationDegree);
18 |
19 |
20 | /**
21 | * Enable blur of the bitmap
22 | *
23 | * @param radius - Radius to blur the image view
24 | */
25 | void setBlur(float radius);
26 |
27 | /**
28 | * Set brightness to the bitmap
29 | *
30 | * @param brightnessValue - value by how much brightness is set to the bitmap
31 | */
32 | void setBrightness(int brightnessValue);
33 |
34 | /**
35 | * set shading effect to bitmap
36 | *
37 | * @param shadingColor - integer value of the color by which the shading effect is to be given
38 | */
39 | void setShading(int shadingColor);
40 |
41 | /**
42 | * set black filter to bitmap
43 | */
44 | void applyBlackFilter();
45 |
46 | /**
47 | * set saturation filter
48 | *
49 | * @param saturationLevel - integer to set saturation level for bitmap
50 | */
51 |
52 | void applySaturationFilter(int saturationLevel);
53 |
54 | /**
55 | * set snow effect to bitmap
56 | */
57 | void applySnowEffect();
58 |
59 |
60 | /**
61 | * set flea effect to the image
62 | */
63 | void applyFleaEffect();
64 |
65 |
66 | /**
67 | * set tint image
68 | *
69 | * @param tintDegree - degree by how much tint is to be applied
70 | */
71 |
72 | void setTintImage(int tintDegree);
73 |
74 | // /**
75 | // * replace the color of image
76 | // * @param fromColor - value color from which replace starts
77 | // * @param targetColor - color value to which color needs to be replaced
78 | // * */
79 | // void replaceColor(int fromColor, int targetColor);
80 |
81 | /**
82 | * flip the image
83 | *
84 | * @param flipType - type of the flip horizontal or vertical
85 | */
86 |
87 | void flipImage(int flipType);
88 |
89 | /**
90 | * sets the watermark to the image
91 | *
92 | * @param watermark - string to be set as watermark
93 | * @param location - {@link Point} where watermark will be displayed
94 | * @param color - {@link Color} font color to be set as watermark
95 | * @param alpha - alpha to be set to watermark
96 | * @param size - size of the watermark text
97 | * @param underline - set true if underline needed else false
98 | */
99 | void setWaterMark(String watermark, Point location, int color, int alpha, int size, boolean underline);
100 |
101 | /**
102 | * resize the image to given width and height
103 | *
104 | * @param width - integer value passed by user
105 | * @param height - integer value passed by user
106 | */
107 | void resizeImage(int width, int height);
108 |
109 | /**
110 | * crop the bitmap to from given x and y position up to the given height and width.
111 | *
112 | * @param startX - float value passed by user
113 | * @param startY - float value passed by user
114 | * @param width - integer value passed by user
115 | * @param height - integer value passed by user
116 | */
117 | void doCrop(float startX, float startY, int width, int height);
118 |
119 | /**
120 | * convert bitmap to sketch bitmap
121 | *
122 | * @param type - 3 for negative, 4 for pencil sketch, 5 for color pencil sketch
123 | * @param threshold - integer value passed by user
124 | */
125 | void sketch(int type, int threshold);
126 |
127 | /**
128 | * set hue filter
129 | * @param huelevel
130 | * @return
131 | */
132 | ColorFilter applyHue(int huelevel);
133 |
134 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/utils/BitmapBuilder.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.utils;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 |
9 | /**
10 | * Manipulate bitmap to calculate sample size, decode bitmaps
11 | *
12 | * @author shilushrestha
13 | * @date 7/3/15
14 | */
15 | public class BitmapBuilder {
16 |
17 | /**
18 | * Decode supplied bitmap and load efficiently in memory
19 | *
20 | * @param resources {@link Resources} location for the bitmap
21 | * @param mFrame id of the bitmap
22 | * @return sampled bitmap
23 | */
24 | public static Bitmap decodeSampledBitmapFromResourcePreview(Resources resources, Integer mFrame) {
25 |
26 | // First decode with inJustDecodeBounds=true to check dimensions
27 | final BitmapFactory.Options options = new BitmapFactory.Options();
28 | options.inJustDecodeBounds = true;
29 | BitmapFactory.decodeResource(resources, mFrame, options);
30 |
31 | // Calculate inSampleSize
32 | options.inSampleSize = calculateInSampleSize(options,
33 | options.outWidth / 2, options.outHeight / 2);
34 |
35 | // Decode bitmap with inSampleSize set
36 | options.inJustDecodeBounds = false;
37 | return BitmapFactory.decodeResource(resources, mFrame, options);
38 | }
39 |
40 | /**
41 | * Used to handle large bitmaps efficiently. Load smaller bitmap in memory.
42 | *
43 | * @param options {@link android.graphics.BitmapFactory.Options} objects of the supplied bitmap
44 | * @param reqWidth the width to scale bitmap to
45 | * @param reqHeight height to scale bitmap to
46 | * @return sampled bitmap
47 | */
48 | public static int calculateInSampleSize(BitmapFactory.Options options,
49 | int reqWidth, int reqHeight) {
50 | // Raw height and width of image
51 | final int height = options.outHeight;
52 | final int width = options.outWidth;
53 | int inSampleSize = 1;
54 |
55 | int heightRatio = (int) Math.ceil(height / (float) reqHeight);
56 | int widthRatio = (int) Math.ceil(width / (float) reqWidth);
57 | if (height > reqHeight || width > reqWidth) {
58 | if (heightRatio > widthRatio) {
59 | inSampleSize = heightRatio;
60 | } else {
61 | inSampleSize = widthRatio;
62 | }
63 | }
64 |
65 | return inSampleSize;
66 | }
67 |
68 | /**
69 | * Combine two bitmaps to create a single bitmap
70 | *
71 | * @param bitmapSelectedPicture selected Image bitmap
72 | * @param bitmapOverlayPicture frame bitmap
73 | * @return combined bitmap
74 | */
75 | public static Bitmap overlapBitmaps(Bitmap bitmapSelectedPicture, Bitmap bitmapOverlayPicture) {
76 | Bitmap bmOverlay = Bitmap.createBitmap(bitmapOverlayPicture.getWidth(),
77 | bitmapOverlayPicture.getHeight(), bitmapOverlayPicture.getConfig());
78 | Canvas canvas = new Canvas(bmOverlay);
79 | canvas.drawBitmap(bitmapSelectedPicture, new Matrix(), null);
80 | canvas.drawBitmap(bitmapOverlayPicture, new Matrix(), null);
81 | return bmOverlay;
82 | }
83 |
84 | /**
85 | * Decode supplied bitmap and load efficiently in memory
86 | *
87 | * @param resources {@link Resources} location for the bitmap
88 | * @param resId id of the bitmap
89 | * @param reqWidth required width of new bitmap
90 | * @param reqHeight required height of new bitmap
91 | * @return sampled bitmap
92 | */
93 | public static Bitmap decodeSampledBitmapFromResource(Resources resources, Integer resId, int reqWidth, int reqHeight) {
94 | // First decode with inJustDecodeBounds=true to check dimensions
95 | final BitmapFactory.Options options = new BitmapFactory.Options();
96 | options.inJustDecodeBounds = true;
97 | BitmapFactory.decodeResource(resources, resId, options);
98 |
99 | // Calculate inSampleSize
100 | options.inSampleSize = calculateInSampleSize(options, reqWidth,
101 | reqHeight);
102 |
103 | // Decode bitmap with inSampleSize set
104 | options.inJustDecodeBounds = false;
105 | return BitmapFactory.decodeResource(resources, resId, options);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hackathon/picfix/widgets/PicFixImageView.java:
--------------------------------------------------------------------------------
1 | package com.hackathon.picfix.widgets;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.ColorFilter;
7 | import android.graphics.Point;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.graphics.drawable.Drawable;
10 | import android.util.AttributeSet;
11 | import android.widget.ImageView;
12 | import android.widget.RelativeLayout;
13 |
14 | import com.hackathon.picfix.filters.Blur;
15 | import com.hackathon.picfix.filters.Brightness;
16 | import com.hackathon.picfix.filters.Flea;
17 | import com.hackathon.picfix.transform.FlipImage;
18 | import com.hackathon.picfix.transform.RotationEffect;
19 | import com.hackathon.picfix.filters.Shading;
20 | import com.hackathon.picfix.filters.Sketch;
21 | import com.hackathon.picfix.filters.Snow;
22 | import com.hackathon.picfix.filters.TintImage;
23 | import com.hackathon.picfix.filters.WaterMark;
24 | import com.hackathon.picfix.filters.BlackFilter;
25 | import com.hackathon.picfix.filters.Hue;
26 | import com.hackathon.picfix.filters.Saturation;
27 | import com.hackathon.picfix.interfaces.CustomFrameInterface;
28 | import com.hackathon.picfix.interfaces.PicFixViewInterface;
29 | import com.hackathon.picfix.utils.BitmapBuilder;
30 |
31 | import java.io.ByteArrayOutputStream;
32 |
33 | /**
34 | * extends {@link ImageView} class to apply all the image editor function
35 | * {@link PicFixViewInterface} is implemented to pass all the editor function
36 | */
37 | public class PicFixImageView extends ImageView implements PicFixViewInterface, CustomFrameInterface {
38 |
39 | private Integer[] mFrames;
40 | private RelativeLayout.LayoutParams mOverlayParams;
41 | private PicFixImageView imgOverlayFrame;
42 | private float blurRadius = 1;
43 | private final Drawable drawable;
44 | private final Context context;
45 | private final Bitmap definedBitmap;
46 |
47 | public PicFixImageView(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 |
50 | drawable = getDrawable();
51 | this.context = context;
52 | definedBitmap = ((BitmapDrawable) this.getDrawable()).getBitmap();
53 | }
54 |
55 |
56 | @Override
57 | public void setRotationTo(float rotationDegree) {
58 | Bitmap rotatedBitmap = RotationEffect.getRotatedBitmap(definedBitmap, rotationDegree);
59 | this.setImageBitmap(rotatedBitmap);
60 | }
61 |
62 | @Override
63 | public void setBlur(float radius) {
64 |
65 | if (radius < 1) {
66 | this.blurRadius = 1;
67 | } else {
68 | this.blurRadius = radius;
69 | }
70 | Bitmap blurredBitmap = Blur.blur(context, definedBitmap, this.blurRadius);
71 | this.setImageBitmap(blurredBitmap);
72 |
73 | }
74 |
75 | @Override
76 | public void setBrightness(int brightnessValue) {
77 | Bitmap brightBitmap = Brightness.getBrightnessEffect(definedBitmap, brightnessValue);
78 | // return final image
79 | this.setImageBitmap(brightBitmap);
80 | }
81 |
82 | @Override
83 | public void setShading(int shadingColor) {
84 |
85 | Bitmap shadedBitmap = Shading.getShadingEffect(definedBitmap, shadingColor);
86 | this.setImageBitmap(shadedBitmap);
87 |
88 | }
89 |
90 | @Override
91 | public void applyBlackFilter() {
92 |
93 | Bitmap blackFiltered = BlackFilter.getBlackFilteredImage(definedBitmap);
94 | this.setImageBitmap(blackFiltered);
95 |
96 | }
97 |
98 | @Override
99 | public void applySaturationFilter(int saturationLevel) {
100 |
101 | Bitmap saturatedBitmap = Saturation.getSaturatedFilter(definedBitmap, saturationLevel);
102 | this.setImageBitmap(saturatedBitmap);
103 | }
104 |
105 | @Override
106 | public void applySnowEffect() {
107 | Bitmap snowEffectBitmap = Snow.getSnowEffectBitmap(definedBitmap);
108 | this.setImageBitmap(snowEffectBitmap);
109 |
110 | }
111 |
112 | @Override
113 | public void applyFleaEffect() {
114 | Bitmap fleaEffectBitmap = Flea.getFleaEffectBitmap(definedBitmap);
115 | this.setImageBitmap(fleaEffectBitmap);
116 |
117 | }
118 |
119 | @Override
120 | public void setTintImage(int tintDegree) {
121 |
122 | Bitmap tintedBitmap = TintImage.getTintImage(definedBitmap, tintDegree);
123 | this.setImageBitmap(tintedBitmap);
124 | }
125 |
126 | @Override
127 | public void flipImage(int flipType) {
128 | Bitmap flippedBitmap = FlipImage.getFlippedImage(definedBitmap, flipType);
129 | this.setImageBitmap(flippedBitmap);
130 | }
131 |
132 | @Override
133 | public void setWaterMark(String watermark, Point location, int color, int alpha, int size, boolean underline) {
134 |
135 | Bitmap waterMarkedBitmap = WaterMark.getWaterMarked(definedBitmap, watermark, location, color, alpha, size, underline);
136 | this.setImageBitmap(waterMarkedBitmap);
137 | }
138 |
139 | @Override
140 | public void setFrames(Integer[] framesId) {
141 | mFrames = framesId;
142 | }
143 |
144 | @Override
145 | public Integer[] getFrames() {
146 | return mFrames;
147 | }
148 |
149 | @Override
150 | public void createFrameOverlay(Context context, PicFixImageView frameImageView, PicFixImageView selectedImageView) {
151 | // mContext = context;
152 | imgOverlayFrame = frameImageView;
153 | mOverlayParams = new RelativeLayout.LayoutParams(selectedImageView.getWidth(), selectedImageView.getHeight());
154 |
155 | mOverlayParams.addRule(RelativeLayout.ALIGN_LEFT, selectedImageView.getId());
156 | mOverlayParams.addRule(RelativeLayout.ALIGN_RIGHT, selectedImageView.getId());
157 | mOverlayParams.addRule(RelativeLayout.ALIGN_TOP, selectedImageView.getId());
158 | mOverlayParams.addRule(RelativeLayout.ALIGN_BOTTOM, selectedImageView.getId());
159 | mOverlayParams.addRule(RelativeLayout.ABOVE, selectedImageView.getId());
160 |
161 | imgOverlayFrame.setImageResource(mFrames[0]);
162 | imgOverlayFrame.setScaleType(ScaleType.FIT_XY);
163 | imgOverlayFrame.setLayoutParams(mOverlayParams);
164 |
165 | }
166 |
167 | @Override
168 | public void setSelectedFrame(int position) {
169 | imgOverlayFrame.setImageBitmap(BitmapBuilder.decodeSampledBitmapFromResourcePreview(
170 | context.getResources(), mFrames[position]));
171 | imgOverlayFrame.setScaleType(ImageView.ScaleType.FIT_XY);
172 | imgOverlayFrame.setLayoutParams(mOverlayParams);
173 |
174 | }
175 |
176 | @Override
177 | public Bitmap getFramedBitmap(PicFixImageView selectedImageView, int position) {
178 | ByteArrayOutputStream bytesOfImage = new ByteArrayOutputStream();
179 | // compressing to 10 percent
180 |
181 | BitmapFactory.Options options = new BitmapFactory.Options();
182 | options.inJustDecodeBounds = true;
183 | options.inSampleSize = 2;
184 |
185 | // Decode bitmap with inSampleSize set
186 | options.inJustDecodeBounds = false;
187 |
188 | Bitmap bitmapOverlayPicture = BitmapFactory.decodeResource(
189 | getResources(), mFrames[position], options);
190 |
191 | Bitmap bitmapSelectedPicture = ((BitmapDrawable) selectedImageView.getDrawable()).getBitmap();
192 |
193 | bitmapOverlayPicture = bitmapOverlayPicture.createScaledBitmap(bitmapOverlayPicture, bitmapSelectedPicture.getWidth(), bitmapSelectedPicture.getHeight(), true);
194 |
195 | Bitmap bitmap = BitmapBuilder.overlapBitmaps(bitmapSelectedPicture, bitmapOverlayPicture);
196 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytesOfImage);
197 |
198 | return bitmap;
199 | }
200 |
201 |
202 | public void resizeImage(int width, int height) {
203 | Bitmap resizedBitmap = Bitmap.createScaledBitmap(definedBitmap, width, height, true);
204 |
205 | this.setImageBitmap(resizedBitmap);
206 | }
207 |
208 | @Override
209 | public void doCrop(float startX, float startY, int width, int height) {
210 | Bitmap resizedBitmap = Bitmap.createBitmap(definedBitmap, (int) startX, (int) startY, width, height);
211 |
212 | this.setImageBitmap(resizedBitmap);
213 | }
214 |
215 | @Override
216 | public void sketch(int type, int threshold) {
217 | this.setImageBitmap(Sketch.changeToSketch(definedBitmap, type, threshold));
218 | }
219 |
220 | @Override
221 | public ColorFilter applyHue(int huelevel) {
222 | return Hue.adjustHue(huelevel);
223 | }
224 | }
225 |
--------------------------------------------------------------------------------