像在photoshop中那样在android中使用搜索栏获取RGB效果?

时间:2014-05-10 05:55:56

标签: android rgb photoshop seekbar

我使用红色,绿色和蓝色的三个搜索栏来改变图像颜色。当这三个搜索条位于中间或极左或极右时,必须显示原始图像。我花了很多时间来解决这个问题。但我无法得到它,请帮我解决这个问题。

我的主要活动是

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;

public class Example extends Activity {

private int seekR, seekG, seekB,color;
SeekBar redSeekBar, greenSeekBar, blueSeekBar;
LinearLayout mScreen;
Bitmap source,destination,result;
ImageView changedImage;
Button show;
LinearLayout linear;
@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
    show=(Button)findViewById(R.id.button1);
    changedImage=(ImageView)findViewById(R.id.changedImage);
    redSeekBar = (SeekBar)findViewById(R.id.mySeekingBar_R);
    greenSeekBar = (SeekBar)findViewById(R.id.mySeekingBar_G);
    blueSeekBar = (SeekBar)findViewById(R.id.mySeekingBar_B);
    linear=(LinearLayout)findViewById(R.id.linear);


    show.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(linear.getVisibility()==View.VISIBLE)
                linear.setVisibility(View.INVISIBLE);
            else
                linear.setVisibility(View.VISIBLE);

            updateBackground();
            redSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
            greenSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
                  blueSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);                
        }
    });   
}

private SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener()
{

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
        // TODO Auto-generated method stub
        updateBackground();
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }


};

    private void updateBackground()
    {

    seekR = redSeekBar.getProgress();
    seekG = greenSeekBar.getProgress();
    seekB = blueSeekBar.getProgress();
    color=0xff000000+ seekR * 0x10000+ seekG * 0x100+ seekB;
    changeBitmapColor( color);
    }

   private void changeBitmapColor( int color) {


    destination = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
    result = destination.copy(Bitmap.Config.ARGB_8888, true);
    Paint p = new Paint();
    ColorFilter filter = new LightingColorFilter(color, 1);
    p.setColorFilter(filter);
    changedImage.setImageBitmap(result);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(result, 0, 0, p);
   }

 }

我的xml文件是

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="106dp"
    android:text="Show" />

<ImageView
    android:id="@+id/changedImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button1"
    android:layout_marginLeft="86dp"
    android:layout_marginTop="14dp"
    android:src="@drawable/myimage" />

   <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical" 
    android:visibility="invisible"
    android:id="@+id/linear">

 <SeekBar 
  android:id="@+id/mySeekingBar_R" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:max="512" 
  android:progress="255" 
  android:paddingTop="10dp"/> 

 <SeekBar 
  android:id="@+id/mySeekingBar_G" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:max="512" 
  android:progress="255"
  android:paddingTop="10dp" />

 <SeekBar 
  android:id="@+id/mySeekingBar_B" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:max="512" 
  android:progress="255" 
  android:paddingTop="10dp"/>

 </LinearLayout>

</RelativeLayout>

请帮我怎么做。谢谢。

1 个答案:

答案 0 :(得分:0)

我对Android很新。但我的想法(用于测试目的)是使用以下方式更改背景:

v.setBackgroundColor(0xFF00FF00);

v是View,在setBackroundColor的参数中,您可以从seekbar插入生成的值。