2014-10-19 126 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