2014-02-27 12 views
0

我正在开发一个客户端 - 服务器应用程序。 客户端是android。 服务器是我的电脑。 服务器正在向客户端发送字节数组,客户端从字节数组构建图像,并通过ImageView显示它们(一帧一帧)。如何从视图对象(SeekBar)发送值到运行后台线程?

我使用AsyncTask打开服务器的套接字并构建图像。到目前为止,一切工作正常。

现在,我想添加SeekBar为了改变图像的亮度。

我的问题是如何将seekbar值发送到构建图像的函数?

public void onClickConnect(View view) 
{ 
    // connect to the server 
    new ConnectTask().execute(""); 
} 

public class ConnectTask extends AsyncTask<String, Bitmap, TcpClient> { 

    @Override 
    protected TcpClient doInBackground(String... message) 
    { 
     //we create a TCPClient object and 
     mTcpClient = new TcpClient(new TcpClient.OnBitmapReceived() { 
      @Override 
      public void bitmapReceived(Bitmap bitmap) { 
       //this method calls the onProgressUpdate 
       publishProgress(bitmap); 
      } 
     }); 
     mTcpClient.run(); 
     return null; 
    } 

    @Override 
    protected void onProgressUpdate(Bitmap... bitmap) { 
     super.onProgressUpdate(bitmap); 

     //iv is the ImageView object that display the images 
     iv.setImageBitmap(bitmap[0]); 
    } 
} 

public class TcpClient {  
    private OnBitmapReceived mBitmapListener = null;  
    public TcpClient(OnBitmapReceived listener) { 
     mBitmapListener = listener; 
    } 
    public void run() {  
    mRun = true;   
    //creating a socket to make the connection with the server 
    .....  
    while (mRun){   
     ..... 
     //build color array 
     **// HERE I NEED THE VALUE FROM THE SEEK BAR**   
     for(int i=0;i<bytePerFrame;i=i+2)     
      { 
       pixel = ((frameBytes[i] << 8) & 0x0000ff00) | (frameBytes[i+1] & 0x000000ff); 
       colors[pixelIndex]=pixel; 
       pixelIndex++; 
      }     
     Bitmap mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
     Canvas c = new Canvas(mBitmap); 
     Paint paint = new Paint(); 
     c.drawBitmap(colors, 0, width, 0, 0, width, height, false, paint);   
     if(mBitmap!=null && mBitmapListener != null) 
      { 
        mBitmapListener.bitmapReceived(mBitmap); 
      }    
     }  
    } 
} 
+0

我想你可以有一个包装类将举行包裹在它的搜索条价值和位图。您可以通过序列化此类将其通过套接字发送。 –

+0

我想通过android更改图像的亮度, 我将像素置于colors数组中 – dan

+0

检查此问题 - http://stackoverflow.com/questions/18958792/how-to-adjust-image-brightness- in-android-with-opencv –

回答

相关问题