2014-10-19 75 views
0

我幾乎建立我的android應用程序,但我有一些麻煩。我的應用程序使用ftp連接在服務器上上傳照片並在屏幕上顯示這些照片。使用「上傳部分」我沒有任何問題,但是當我選擇一張照片並且想要在屏幕上顯示時,我遇到了一些問題。看起來像我的圖像模糊或碎片化。我認爲這是從redimensioning,但在這種方式,我嘗試了很多算法...不成功 請告訴我如何顯示在屏幕上從這個FTP服務器的圖像,圖像顯示質量好,沒有「模糊或零碎」的部分,謝謝你從FTP服務器在屏幕上顯示圖像

這是我的 「形象秀」 類...

import java.io.BufferedInputStream; 
import java.io.File; 
import java.io.IOException; 
import java.io.InputStream; 

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.ImageView; 

@SuppressLint("NewApi") 
public class FaceDetection extends Activity { 
public String o; 
public ImageView viu; 
public Bitmap bit; 
public Bitmap myBitmap; 
File file; 
    InputStream a=null; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.poza); 
    a=NextActivity.aa; 
    viu=(ImageView)findViewById(R.id.imageView1); 
    o=getIntent().getStringExtra("CaleOptiune"); 
      setData(o); 
      initData(); 
      bit=getBit(); 
      viu.setImageBitmap(bit); 

     } 


public Bitmap getBit(){   
     BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options(); 
     BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565; 
     myBitmap = BitmapFactory.decodeResource(getResources(), 
     R.drawable.index, BitmapFactoryOptionsbfo); 
     if(a!=null){Log.e("asdasdsadsadas","Streamul este incarcat");}else{Log.e("asdasdsadsadas","E nullllllll");} 
     myBitmap = BitmapFactory.decodeStream(new BufferedInputStream(a)); 
     return myBitmap; 
} 



public void initData(){ 

     File file=new File(o); 
     try { 
     Log.e("Fisierul curent este",""+Logare.ftpClient.getWorkingDirectory()); 
    } catch (IOException e2) { 
     // TODO Auto-generated catch block 
     e2.printStackTrace(); 
    } 
     Log.e("File","Fisier creat din calea "+o); 
     Log.e("File name",""+file.getName()); 
    try { 
     a = Logare.ftpClient.ftpClient.retrieveFileStream(file.getName()); 
     Logare.ftpClient.ftpClient.completePendingCommand(); 
    } catch (Exception e1) { 
     Log.e("asdasdsadsadas","Nu s-a instantiat InputSteamul"); 
    } 

    } 


public void setData(String o) { 
    this.o = o; 

} 

}

回答

0

解碼和顯示的圖像似乎是確定。你可以通過Loading Large Bitmaps Efficiently來改善它。

我不知道,但我覺得你的問題應該是這個問題:https://code.google.com/p/android/issues/detail?id=6066

嘗試創建類:

public class FlushedInputStream extends FilterInputStream { 

    public FlushedInputStream(InputStream inputStream) { 
     super(inputStream); 
    } 

    @Override 
    public long skip(long n) throws IOException { 
     long totalBytesSkipped = 0L; 
     while (totalBytesSkipped < n) { 
      long bytesSkipped = in.skip(n - totalBytesSkipped); 
      if (bytesSkipped == 0L) { 
       int by_te = read(); 
       if (by_te < 0) { 
        break; // we reached EOF 
       } else { 
        bytesSkipped = 1; // we read one byte 
       } 
      } 
      totalBytesSkipped += bytesSkipped; 
     } 
     return totalBytesSkipped; 
    } 
} 

及用途:

bm = BitmapFactory.decodeStream(new FlushedInputStream(entity.getContent()));

+0

我試着這個班但是...不工作...我遇到同樣的問題 – 2014-10-20 15:28:31

+0

好的,你可以請發送printScreen的壞載圖片?感謝名單。 – vzoha 2014-10-21 08:28:09

+0

http://postimg.org/image/605la4gib/ – 2014-10-21 10:28:38

相關問題