Android Bitmap 改变大小

/**
	 * Returns a Bitmap representing the thumbnail of the specified Bitmap.
	 * The size of the thumbnail is defined by the dimension
	 * android.R.dimen.launcher_application_icon_size.
	 *
	 * This method is not thread-safe and should be invoked on the UI thread only.
	 *
	 * @param bitmap The bitmap to get a thumbnail of.
	 * @param context The application's context.
	 *
	 * @return A thumbnail for the specified bitmap or the bitmap itself if the
	 *         thumbnail could not be created.
	 */
	public static Bitmap createBitmapThumbnail(Bitmap bitmap, Context context)
	{
		 if(FusionField.iconWidth == -1&&(FusionField.screenWidth == 800 && FusionField.screenHeight == 480)){
				FusionField.iconWidth = 80;
				FusionField.iconHeight = 98;
			
		}
		else if (FusionField.iconWidth == -1)
		{
				FusionField.iconWidth = 60;
				FusionField.iconHeight = 82;
		}

		final int bitmapWidth = bitmap.getWidth();
		final int bitmapHeight = bitmap.getHeight();

		Log.e("dean xiang", "" + bitmapWidth + ":" + bitmapHeight);
		if (FusionField.iconWidth > 0 && FusionField.iconHeight > 0)
		{

			final Bitmap.Config c = Bitmap.Config.ARGB_8888;
			final Bitmap thumb = Bitmap
					.createBitmap(FusionField.iconWidth, FusionField.iconHeight, c);
			final Canvas canvas = sCanvas;
			final Paint paint = sPaint;

			canvas.setBitmap(thumb);
			paint.setDither(false);
			paint.setFilterBitmap(true);
			//			int offsetX = Math.abs(sIconWidth - bitmapWidth) / 2;
			//			int offsetY = Math.abs(sIconHeight - bitmapHeight) / 2;
			//			
			//			sBounds.set(offsetX, offsetY, bitmapWidth + offsetX,
			//					bitmapHeight + offsetY);
			//			sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
			//			canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
			
			sBounds.set(0, 0, FusionField.iconWidth, FusionField.iconHeight);
			sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
			canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
			return thumb;
		}

		return bitmap;
	}
上一篇:ORACLE 12C连接时报ORA28040和ORA01017的错误


下一篇:《Scala程序设计》阅读书摘