Android着色图像具有2种不同颜色
我试着把图像的左半部分涂成橙色,右半部分涂成栗色。我写了我的代码,但每当我尝试时,它只返回纯橙色和栗色。这就是我想做的 我想用橙色和栗色染上左右两边的颜色 像这样,我的工作方式与示例不同。这是我的密码Android着色图像具有2种不同颜色,android,colors,bitmap,tint,Android,Colors,Bitmap,Tint,我试着把图像的左半部分涂成橙色,右半部分涂成栗色。我写了我的代码,但每当我尝试时,它只返回纯橙色和栗色。这就是我想做的 我想用橙色和栗色染上左右两边的颜色 像这样,我的工作方式与示例不同。这是我的密码 public Bitmap toHokie(Bitmap bmpOriginal) { int width, height; Bitmap bmOut = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpO
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;
}
公共位图toHokie(位图bmpOriginal){
int宽度、高度;
位图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);
对于(int j=0;j
实际上,在我第二次尝试时,它现在比以前更好了,但它仍然是有线的。。。像这样
我就这样修好了
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;
}
公共位图toHokie(位图bmpOriginal){
int宽度、高度;
位图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);
对于(int j=0;j
这是一个xml文件
<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>
添加颜色,然后向它们添加alpha属性,我想应该可以。寻找相同的颜色,你得到解决方案了吗?如果是的话,你能把它作为答案贴出来吗?你将有机会获得一些分数,因为很多人都在寻找这个答案(见浏览100多次)
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);