2014-02-27 41 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 –

回答

相關問題