图像阵列

时间:2015-12-02 19:10:32

标签: android android-image

在我的应用程序中,我的CustomSwipeAdapter包含图像和文本信息。 我在这段代码中设置了图像:

private int[] image_resources = {
        R.drawable.wl1,
        R.drawable.wl2,
        R.drawable.wl3,
        R.drawable.wl4,
        R.drawable.wl5,
        R.drawable.wl6,
        R.drawable.wl7,
        R.drawable.wl8,
        R.drawable.wl9,
        R.drawable.wl10}; and so on..

现在我可以从Parse.com下载图片了:

                  ParseFile backgroundImage = (ParseFile) parseObj.get("backgroundImage");
                    backgroundImage.getDataInBackground(new GetDataCallback() {
                        public void done(byte[] data, ParseException e) {
                            if (e == null) {

                                try {
                                    bitmap_backgroundImage = BitmapFactory.decodeByteArray(data, 0, data.length);
                                    ContextWrapper cw1 = new ContextWrapper(getApplicationContext());
                                    File directory = cw1.getDir("backgroundimage", Context.MODE_PRIVATE);
                                    if (!directory.exists()) {
                                        directory.mkdir();
                                    }
                                    File mypath1 = new File(directory, "backgroundimage.png");

                                    FileOutputStream fos = new FileOutputStream(mypath1);
                                    bitmap_backgroundImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
                                    fos.close();

                                } catch (Exception e1) {
                                    Log.e("SAVE_IMAGE", e1.getMessage(), e1);
                                }
                            } else {

                            }
                        }
                    });

并将其设置为其他活动的背景:

public void setMainImage(){

try{
    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    File directory = cw.getDir("menuimage", Context.MODE_PRIVATE);
    File mypath = new File(directory, "menuimage.png");
    Bitmap mainimage = BitmapFactory.decodeFile(mypath.getAbsolutePath());
    ImageView main = (ImageView) findViewById(R.id.imageView_main);
    main.setImageBitmap(mainimage);
    main.setScaleType(ImageView.ScaleType.CENTER_CROP);
}  catch (Exception e) {
        e.printStackTrace();
    }

}

所以我的问题是:是否可以将图像设置为具有相同代码的图像,我只将图像设置为imageView?

如果我能做到这一点,请告诉我如何做。如果有可能的话还有更多细节 - 我在java中真的很新。 谢谢。

0 个答案:

没有答案
相关问题