从ftp服务器在屏幕上显示图像

时间:2014-10-19 09:58:32

标签: android ftp imageview

我几乎构建了我的android应用程序,但我遇到了一些麻烦。我的应用程序使用ftp连接在服务器上上传照片,并在屏幕上显示这些照片。使用"上传部分"我没有问题,但当我选择一张照片而我想在屏幕上显示时,我遇到了一些问题。好像我的图像模糊或碎片化。我认为这是来自redimensioning,但是通过这种方式我尝试了许多算法......不成功 请告诉我如何在屏幕上显示来自此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;

 }

}

1 个答案:

答案 0 :(得分: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()));