Reputation: 139
I am trying to tint the image left half with orange, right with maroon color. I wrote my code, but whenever I tried, it returned just solid orange and maroon color. So this is what I am trying to do.
I want to tint the left and right with orange and maroon with good amount so it will be like
Like this, mine is not working like the example. Here is my code.
public Bitmap toHokie(Bitmap bmpOriginal) {
int width, height;
Bitmap bmOut = Bitmap.createBitmap(bmpOriginal.getWidth(),
bmpOriginal.getHeight(), bmpOriginal.getConfig());
height = bmOut.getHeight();
width = bmOut.getWidth();
int orangeFilter = new Color().rgb(255, 165, 0);
int maroonFilter = new Color().rgb(139, 0, 0);
for (int j = 0; j < height - 1; j++) {
for (int i = 0; i < width / 2 - 1; i++) {
int newColor = (int) ((double) (bmOut.getPixel(i, j) * 0.3) + ((double) (orangeFilter * 0.7)));
bmOut.setPixel(i, j, newColor);
}
}
for (int j = 0; j < height - 1; j++) {
for (int i = width / 2; i < width - 1; i++) {
double newColor = (bmOut.getPixel(i, j) * 0.3 + maroonFilter * 0.7);
bmOut.setPixel(i, j, (int) newColor);
}
}
return bmOut;
}
Actually, for my second try, it is now better than the before, but still it is wired... like this
I fixed like this.
public Bitmap toHokie(Bitmap bmpOriginal) {
int width, height;
Bitmap bmOut = Bitmap.createBitmap(bmpOriginal.getWidth(),
bmpOriginal.getHeight(), bmpOriginal.getConfig());
height = bmOut.getHeight();
width = bmOut.getWidth();
int orangeFilter = new Color().rgb(255, 165, 0);
int maroonFilter = new Color().rgb(139, 0, 0);
for (int j = 0; j < height - 1; j++) {
for (int i = 0; i < width / 2 - 1; i++) {
int newColor = (int) ((bmpOriginal.getPixel(i, j) * 0.7) + ((orangeFilter * 0.3)));
bmOut.setPixel(i, j, newColor);
}
}
for (int j = 0; j < height - 1; j++) {
for (int i = width / 2; i < width - 1; i++) {
double newColor = (bmpOriginal.getPixel(i, j) * 0.3 + maroonFilter * 0.7);
bmOut.setPixel(i, j, (int) newColor);
}
}
return bmOut;
}
Upvotes: 2
Views: 1221
Reputation: 91
this is xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="@drawable/sachin_bg1" />
<LinearLayout
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:id="@+id/layout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#4a8cd5"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="0.5"
android:background="#f21616"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
use this code in onCreate method
LinearLayout layout1 = (LinearLayout) findViewById(R.id.layout1);
Drawable background1 = layout1.getBackground();
background1.setAlpha(100);
LinearLayout layout2 = (LinearLayout) findViewById(R.id.layout2);
Drawable background2 = layout2.getBackground();
background2.setAlpha(100);
Upvotes: 1