0

私のアプリでは、スプラッシュ スクリーンが開始されたときに、URL から画像をダウンロードしています。アプリの別のアクティビティで同じ画像を使用したいと考えています。以下は、画像をダウンロードするための私のコードです

public void DownloadImage(String fileName)      
    {

        try 
        {
                           URL url = new URL(main.BannerImage); //you can write here any link                          
                           File file = new File(fileName);
                           Log.e("file ",""+file);

                           URLConnection ucon = url.openConnection();                          
                           InputStream is = ucon.getInputStream();                         
                           BufferedInputStream bis = new BufferedInputStream(is);
                           ByteArrayBuffer baf = new ByteArrayBuffer(50);
                           int current = 0;
                           while ((current = bis.read()) != -1) 
                           {
                                 baf.append((byte) current);
                           }

                           FileOutputStream fos = new FileOutputStream(file);
                           fos.write(baf.toByteArray());
                           fos.close();
        }
        catch (IOException e) 
        {
                            Log.e("Error: ","" + e);
        }

別のアクティビティで背景ソースとして画像を取得するにはどうすればよいですか? 友達を助けてください

4

1 に答える 1

0

画像をSDカードに保存し、パスを使用して次のアクティビティに送信できます

intent.putExtras("filename","filepathname"); 

を使用して次のアクティビティに参加します

getIntent().getExtras().getString("filename") 

これから、前のアクティビティからファイルパスを取得でき、特定のファイルパスから画像を取得できます。

画像をビットマップに変換し、Parcelable などを使用して次のアクティビティに渡すことができます

Bundle extras = new Bundle(); 
extras.putParcelable("data",bitmap);
Intent intent=new Intent(currentActivity.this,nextImage.class); 
intent.putExtras(extras);
startActivity(intent);
finish();

次のアクティビティでは、ビットマップを次のように取得できます

 Bitmap  image=getIntent().getExtras().getParcelable("data");
于 2011-07-12T09:30:45.917 に答える