2011-06-30 34 views
1

我寫了一個模塊,創建一個覆蓋了imageView的cameraview來拍攝照片,我的問題是,因爲我無法在「res」文件夾中傳遞圖像,所以我需要將它放在「assets 「,在純java中,它一切正常,但我天堂不知道在我導出模塊後將」assets「文件放置在鈦項目中的位置。 當我調用帶有IOException的方法時,它崩潰。 由於Titanium中的資產文件夾

FrameLayout fl = new FrameLayout(this); 
    SurfaceView preview = new SurfaceView(this); 
    ImageView footerCam = new ImageView(this); 
    LinearLayout ll = new LinearLayout(this); 

    LinearLayout.LayoutParams shareParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    footerCam.setLayoutParams(shareParams); 
    ll.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); 

    ll.addView(footerCam); 
    fl.addView(preview); 
    fl.addView(ll); 

    setContentView(fl); 
    camera = Camera.open(); 

    try 
    { 
    AssetManager am = getAssets(); 
    BufferedInputStream buf = new BufferedInputStream(am.open("footer1.png")); 
    Bitmap bitmap = BitmapFactory.decodeStream(buf); 
    footerCam.setImageBitmap(bitmap); 
    buf.close(); 
    } 
    catch (IOException e) 
    { 
     Log.e("IMG","@@@@@@@@@@@@@@@@@@@@@@@ ERROR LOADING IMAGE"); 
     e.printStackTrace(); 
    } 

這是一段代碼,其中i聲明按鈕並將它指定從資產文件夾的圖像,但只在機器人的工作原理,當我部署模塊並將其包括在鈦它落入IOException的,我需要在哪裏放置文件「footer1.png」或「assets」文件夾?

回答

0

我用這種worksround

int resID = getResources().getIdentifier("IMG.png", "drawable", "it.temp"); 
// or 
int resID = getResources().getIdentifier("it.temp:drawable/icon",null,null); 

button.setBackgroundResource(resID);// or whatever you need 

的管理,但你必須把圖像在同一個包的源代碼。