English 中文(简体)
地图太长
原标题:drawBitmap takes too long

《刑法》

        URL uri = new URL(photoUrl);
            URLConnection connection = uri.openConnection();
            Log.i(TAG, "connecting...");
            connection.connect();
            Log.i(TAG, "connected");
            Log.i(TAG, "building Bitmap...");

            InputStream is = connection.getInputStream();
            //BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024);

            File myfile = new File(getApplicationContext().getCacheDir(), "wallpaper.tmp");
            myfile.createNewFile();
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(myfile));

            byte buf[]=new byte[1024];
            int len;
            while((len=is.read(buf))>0)
            out.write(buf,0,len);
            out.close();
            is.close();

            Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());
            //Bitmap bmp = BitmapFactory.decodeStream(bis);

            Log.i(TAG, "builded Bitmap");               
            Log.i(TAG, "showing bitmap...");


            //int scale;
            Matrix matrix = new Matrix();
            matrix.setScale(0.1F, 0.1F);
            //if (bmp.getWidth() < bmp.getHeight()){
            //  scale = canvas.getWidth()/bmp.getWidth();
            //}else{
            //  scale = canvas.getHeight()/bmp.getHeight();
            //}
            //matrix.postScale(scale, scale, bmp.getWidth(), bmp.getHeight());
            //matrix.postScale(0.5F, canvas.getWidth()/bmp.getWidth());

            //Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), true);

            //Paint p = new Paint();
            //p.setFilterBitmap(true);


            //try{
            canvas.drawBitmap(bmp, matrix, null);
            //}catch(NullPointerException exc){
            //  //why do we get this??
            //  Log.d(TAG, "NullPointerException drawing canvas. why?");
            //  return;
            //}

Now what happens is that drawBitmap is blocking since 5 minutes... Any ideas?

最佳回答

You might get better performance by creating a scaled bitmap in the first place.

Bitmap bmp = BitmapFactory.decodeFile(myfile.getPath());
bmp = bmp.createScaledBitmap(bmp, width, height, true);

Then you won t have to use a matrix when drawing it out to the screen either.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签