相关疑难解决方法(0)

以编程方式从Android的内置Gallery应用程序中获取/选择图像

我正试图在我的应用程序内打开Gallery内置应用程序中的图像/图片.

我有一张图片的URI(图片位于SD卡上).

你有什么建议吗?

android image gallery android-intent

265
推荐指数
12
解决办法
30万
查看次数

BitmapFactory.decodeStream在设置选项时返回null

我有问题BitmapFactory.decodeStream(inputStream).在没有选项的情况下使用它时,它将返回一个图像.但是当我将它与选项一起使用时,.decodeStream(inputStream, null, options)它永远不会返回Bitmaps.

我要做的是在实际加载之前对Bitmap进行下采样以节省内存.我读过一些很好的指南,但都没有使用.decodeStream.

工作很精细

URL url = new URL(sUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);
Run Code Online (Sandbox Code Playgroud)

什么都不行

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);

InputStream is = connection.getInputStream();

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeStream(is, null, options);

Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) >= Math.abs(options.outWidth - TARGET_WIDTH);

if (options.outHeight * options.outWidth * 2 >= 200*100*2){
    // Load, …
Run Code Online (Sandbox Code Playgroud)

java android image bitmap

87
推荐指数
2
解决办法
6万
查看次数

带有rewind()/ reset()功能的java文件输入

我需要编写一个函数,它接受某种输入流的东西(例如一个InputStream或一个FileChannel),以便在两次传递中读取一个大文件:一次预先计算一些容量,二次做"真正的"工作.我不希望一次将整个文件加载到内存中(除非它很小).

是否有适当的Java类提供此功能?FileInputStream本身不支持mark()/ reset().我认为BufferedInputStream确实如此,但我不清楚它是否必须存储整个文件来执行此操作.

C很简单,你只需使用fseek(),ftell()和rewind().:-(

java io stream

33
推荐指数
5
解决办法
4万
查看次数

Android:SkImageDecoder :: Factory返回null

我正在使用我的localhost来获取图像并在ImageView中查看.由于某种原因,我得到Factory返回null错误.我已多次查看代码,但我没有看到错误.任何帮助,将不胜感激!

GalleryZoom.java

public class Zoom extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.gallery_zoom);

        String selection = getIntent().getExtras().getString("image");
        Toast.makeText(this, selection, Toast.LENGTH_LONG).show();

        new backgroundLoader().execute();       
    }


    private class backgroundLoader extends AsyncTask<Void, Void, Void> {
        Bitmap bmp;

        @Override
        protected Void doInBackground(Void... params) {

            bmp = DecodeBitmapSampleSize(getIntent().getExtras().getString("image"), 48, 64);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            ImageView image = (ImageView) findViewById(R.id.imageZoom);
            image.setImageBitmap(bmp);
        }

    }

    public Bitmap DecodeBitmapSampleSize (String strURL, int reqWidth, int reqHeight) {
        InputStream in = …
Run Code Online (Sandbox Code Playgroud)

android

29
推荐指数
3
解决办法
6万
查看次数

如何缓存InputStream以供多种用途

我有一个文件的InputStream,我使用apache poi组件来读取它像这样:

POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
Run Code Online (Sandbox Code Playgroud)

问题是我需要多次使用相同的流,POIFSFileSystem在使用后关闭流.

从输入流缓存数据然后将更多输入流提供给不同的POIFSFileSystem的最佳方法是什么?

编辑1:

通过缓存我的意思是存储供以后使用,而不是作为加速应用程序的方法.最好是将输入流读入数组或字符串,然后为每次使用创建输入流?

编辑2:

很抱歉重新打开这个问题,但在桌面和Web应用程序中工作时条件有所不同.首先,我从tomcat web app中的org.apache.commons.fileupload.FileItem获取的InputStream不支持标记,因此无法重置.

其次,我希望能够将文件保存在内存中,以便在处理文件时更快地访问和减少io问题.

java caching inputstream apache-poi

25
推荐指数
3
解决办法
4万
查看次数