2011-06-30 37 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 

的管理,但你必须把图像在同一个包的源代码。