drawBitmap时间太长 [英] drawBitmap takes too long
本文介绍了drawBitmap时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好这里是code:
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;
//}
现在发生的事情是drawBitmap是因为5分钟拦截...
任何想法?
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.
这篇关于drawBitmap时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文