Android高级模糊技术

展开阅读全文

android桌面图片变模糊

02-26

自己做了个桌面,获取应用图标跟原来的桌面相比变模糊了是怎么回事?大小一样大。rn布局是:rnrn rn rn rn rn rn rn rnrn获取app的代码:rnrn final PackageManager packageManager = getPackageManager();rn final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);rn mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);rn rn //get all appsrn final List apps = packageManager.queryIntentActivities(mainIntent, 0);rn rn GridView appPage = (GridView) findViewById(R.id.all_app_grid);rn appPage.setAdapter(new AppAdapter(this, apps)); rnrn在监听器中获取app图标的代码是:rnrn Bitmap bmp = Utilities.createIconBitmap(appInfo.loadIcon(pm), mContext); rn appItem.mAppIcon.setImageDrawable(appInfo.loadIcon(pm));rnrnstatic Bitmap createIconBitmap(Drawable icon, Context context) rn synchronized (sCanvas) // we share the statics :-(rn if (sIconWidth == -1) rn initStatics(context);rn rnrn int width = sIconWidth;rn int height = sIconHeight;rnrn if (icon instanceof PaintDrawable) rn PaintDrawable painter = (PaintDrawable) icon;rn painter.setIntrinsicWidth(width);rn painter.setIntrinsicHeight(height);rn else if (icon instanceof BitmapDrawable) rn // Ensure the bitmap has a density.rn BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;rn Bitmap bitmap = bitmapDrawable.getBitmap();rn if (bitmap.getDensity() == Bitmap.DENSITY_NONE) rn bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());rn rn rn int sourceWidth = icon.getIntrinsicWidth();rn int sourceHeight = icon.getIntrinsicHeight();rnrn if (sourceWidth > 0 && sourceHeight > 0) rn // There are intrinsic sizes.rn if (width < sourceWidth || height < sourceHeight) rn // It's too big, scale it down.rn final float ratio = (float) sourceWidth / sourceHeight;rn if (sourceWidth > sourceHeight) rn height = (int) (width / ratio);rn else if (sourceHeight > sourceWidth) rn width = (int) (height * ratio);rn rn else if (sourceWidth < width && sourceHeight < height) rn // Don't scale up the iconrn width = sourceWidth;rn height = sourceHeight;rn rn rnrn // no intrinsic size --> use default sizern int textureWidth = sIconTextureWidth;rn int textureHeight = sIconTextureHeight;rnrn final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,rn Bitmap.Config.ARGB_8888);rn final Canvas canvas = sCanvas;rn canvas.setBitmap(bitmap);rnrn final int left = (textureWidth-width) / 2;rn final int top = (textureHeight-height) / 2;rnrn if (false) rn // draw a big box for the icon for debuggingrn canvas.drawColor(sColors[sColorIndex]);rn if (++sColorIndex >= sColors.length) sColorIndex = 0;rn Paint debugPaint = new Paint();rn debugPaint.setColor(0xffcccc00);rn canvas.drawRect(left, top, left+width, top+height, debugPaint);rn rnrn sOldBounds.set(icon.getBounds());rn icon.setBounds(left, top, left+width, top+height);rn icon.draw(canvas);rn icon.setBounds(sOldBounds);rn canvas.setBitmap(null);rnrn return bitmap;rn rn 问答

没有更多推荐了,返回首页