Java Code Examples for android.graphics.Bitmap#getHeight()

The following examples show how to use android.graphics.Bitmap#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapUtil.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 将彩色图转换为灰度图
 *
 * @param img 源Bitmap
 * @return 返回转换好的位图
 */
public static Bitmap convertGreyImg(Bitmap img) {
    int width = img.getWidth(); // 获取位图的宽
    int height = img.getHeight(); // 获取位图的高

    int[] pixels = new int[width * height]; // 通过位图的大小创建像素点数组

    img.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];

            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);

            grey = (int) ((float) red * 0.3 + (float) green * 0.59 + (float) blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap result = Bitmap.createBitmap(width, height, Config.RGB_565);
    result.setPixels(pixels, 0, width, 0, 0, width, height);
    return result;
}
 
Example 2
Source File: CropSquareTransformation.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  mWidth = (source.getWidth() - size) / 2;
  mHeight = (source.getHeight() - size) / 2;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 3
Source File: ThumbnailResource.java    From pixymeta-android with Eclipse Public License 1.0 6 votes vote down vote up
private IRBThumbnail createThumbnail(Bitmap thumbnail) throws IOException {
	// Create memory buffer to write data
	ByteArrayOutputStream bout = new ByteArrayOutputStream();
	// Compress the thumbnail
	try {
		thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bout);
	} catch (Exception e) {
		e.printStackTrace();
	}
	byte[] data = bout.toByteArray();
	this.id = ImageResourceID.THUMBNAIL_RESOURCE_PS5;
	// Write thumbnail dimension
	this.width = thumbnail.getWidth();
	this.height = thumbnail.getHeight();
	// Padded row bytes = (width * bits per pixel + 31) / 32 * 4.
	this.bitsPerPixel = 24;
	this.numOfPlanes = 1;
	this.paddedRowBytes = (width*bitsPerPixel + 31)/32*4;
	// Total size = widthbytes * height * planes
	this.totalSize = paddedRowBytes*height*numOfPlanes;
	// Size after compression. Used for consistency check.
	this.compressedSize = data.length;
	this.dataType = Thumbnail.DATA_TYPE_KJpegRGB;
		
	return new IRBThumbnail(width, height, dataType, data);
}
 
Example 4
Source File: ImageUtil.java    From ImageSelector with Apache License 2.0 6 votes vote down vote up
public static Bitmap zoomBitmap(Bitmap bm, int reqWidth, int reqHeight) {
    // 获得图片的宽高
    int width = bm.getWidth();
    int height = bm.getHeight();
    // 计算缩放比例
    float scaleWidth = ((float) reqWidth) / width;
    float scaleHeight = ((float) reqHeight) / height;
    float scale = Math.min(scaleWidth, scaleHeight);
    // 取得想要缩放的matrix参数
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);
    // 得到新的图片
    Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
            true);
    return newbm;
}
 
Example 5
Source File: RoundedCornersTransformation.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 6
Source File: NMapViewerResourceProvider.java    From maps.android with Apache License 2.0 5 votes vote down vote up
private Bitmap getBitmapWithText(int resourceId, String strNumber, int fontColor, float fontSize, float offsetY) {
	Bitmap bitmapBackground = BitmapFactory.decodeResource(mContext.getResources(), resourceId);

	int width = bitmapBackground.getWidth();
	int height = bitmapBackground.getHeight();
	//Log.i(LOG_TAG, "getBitmapWithText: width=" + width + ", height=" + height + ", density=" + bitmapBackground.getDensity());

	Bitmap textBitmap = Bitmap.createBitmap(width, height, BITMAP_CONFIG_DEFAULT);

	Canvas canvas = new Canvas(textBitmap);

	canvas.drawBitmap(bitmapBackground, 0, 0, null);

	// set font style
	mTextPaint.setColor(fontColor);
	// set font size
	mTextPaint.setTextSize(fontSize * mScaleFactor);
	// set font type
	if (POI_FONT_TYPEFACE != null) {
		mTextPaint.setTypeface(POI_FONT_TYPEFACE);
	}

	// get text offset		
	mTextPaint.getTextBounds(strNumber, 0, strNumber.length(), mTempRect);
	float offsetX = (width - mTempRect.width()) / 2 - mTempRect.left;
	if (offsetY == 0.0F) {
		offsetY = (height - mTempRect.height()) / 2 + mTempRect.height();
	} else {
		offsetY = offsetY * mScaleFactor + mTempRect.height();
	}

	//Log.i(LOG_TAG, "getBitmapWithText: number=" + number + ", focused=" + focused);
	//Log.i(LOG_TAG, "getBitmapWithText: offsetX=" + offsetX + ", offsetY=" + offsetY + ", boundsWidth=" + mTempRect.width() + ", boundsHeight=" + mTempRect.height());

	// draw text
	canvas.drawText(strNumber, offsetX, offsetY, mTextPaint);

	return textBitmap;
}
 
Example 7
Source File: ImageUtils.java    From v2ex with Apache License 2.0 5 votes vote down vote up
/**
 * 获取缩放的bitmap
 * @param context
 * @param imageResId
 * @param maxWidth
 * @param maxHeight
 * @return
 */
public static Bitmap getScaledBitmap(Context context, int imageResId, int maxWidth, int maxHeight) {
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    // If we have to resize this image, first get the natural bounds.
    decodeOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(context.getResources(), imageResId, decodeOptions);
    int actualWidth = decodeOptions.outWidth;
    int actualHeight = decodeOptions.outHeight;
    Log.d(TAG, "Actual width: " + actualWidth + ", actual height: " + actualHeight);

    // Then compute the dimensions we would ideally like to decode to.
    int desiredWidth = getResizedDimension(maxWidth, maxHeight,
            actualWidth, actualHeight);
    int desiredHeight = getResizedDimension(maxHeight, maxWidth,
            actualHeight, actualWidth);
    Log.d(TAG, "Desired width: " + desiredWidth + ", desired height: " + desiredHeight);

    // Decode to the nearest power of two scaling factor.
    decodeOptions.inJustDecodeBounds = false;
    // TODO(ficus): Do we need this or is it okay since API 8 doesn't support it?
    // decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
    decodeOptions.inSampleSize =
            findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
    Bitmap tempBitmap = BitmapFactory.decodeResource(context.getResources(), imageResId, decodeOptions);
    // If necessary, scale down to the maximal acceptable size.
    if (tempBitmap != null && (tempBitmap.getWidth() > desiredWidth ||
            tempBitmap.getHeight() > desiredHeight)) {
        bitmap = Bitmap.createScaledBitmap(tempBitmap,
                desiredWidth, desiredHeight, true);
        tempBitmap.recycle();
    } else {
        bitmap = tempBitmap;
    }
    return bitmap;
}
 
Example 8
Source File: CropView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updateBitmap(Bitmap bitmap, int rotation) {
    float ps = width / bitmap.getWidth();
    scale *= ps;
    width = bitmap.getWidth();
    height = bitmap.getHeight();
    updateMinimumScale();
    float[] values = new float[9];
    matrix.getValues(values);
    matrix.reset();
    matrix.postScale(scale, scale);
    matrix.postTranslate(values[2], values[5]);
    updateMatrix();
}
 
Example 9
Source File: PixelizeIndicator.java    From imageprogressbar with Apache License 2.0 5 votes vote down vote up
/**
 * This method of image pixelization utilizes the bitmap scaling operations built
 * into the framework. By downscaling the bitmap and upscaling it back to its
 * original size (while setting the filter flag to false), the same effect can be
 * achieved with much better performance.
 */
public BitmapDrawable builtInPixelization(float pixelizationFactor, Bitmap bitmap) {

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    int downScaleFactorWidth = (int) (pixelizationFactor * width);
    downScaleFactorWidth = downScaleFactorWidth > 0 ? downScaleFactorWidth : 1;
    int downScaleFactorHeight = (int) (pixelizationFactor * height);
    downScaleFactorHeight = downScaleFactorHeight > 0 ? downScaleFactorHeight : 1;

    int downScaledWidth = width / downScaleFactorWidth;
    int downScaledHeight = height / downScaleFactorHeight;

    Bitmap pixelatedBitmap = Bitmap.createScaledBitmap(bitmap, downScaledWidth,
            downScaledHeight, false);

    /* Bitmap's createScaledBitmap method has a filter parameter that can be set to either
     * true or false in order to specify either bilinear filtering or point sampling
     * respectively when the bitmap is scaled up or now.
     *
     * Similarly, a BitmapDrawable also has a flag to specify the same thing. When the
     * BitmapDrawable is applied to an ImageView that has some scaleType, the filtering
     * flag is taken into consideration. However, for optimization purposes, this flag was
     * ignored in BitmapDrawables before Jelly Bean MR1.
     *
     * Here, it is important to note that prior to JBMR1, two bitmap scaling operations
     * are required to achieve the pixelization effect. Otherwise, a BitmapDrawable
     * can be created corresponding to the downscaled bitmap such that when it is
     * upscaled to fit the ImageView, the upscaling operation is a lot faster since
     * it uses internal optimizations to fit the ImageView.
     * */

    Bitmap upscaled = Bitmap.createScaledBitmap(pixelatedBitmap, width, height, false);
    return new BitmapDrawable(context.getResources(), upscaled);
}
 
Example 10
Source File: MiscUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Bitmap scaleBitmap(Bitmap bitmap, int width, int height) {
    int oHeight = bitmap.getHeight();
    int oWidth = bitmap.getWidth();
    int sqr = oHeight > oWidth ? oHeight : oWidth;

    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    Bitmap background = Bitmap.createBitmap(sqr, sqr, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(background);
    canvas.drawBitmap(bitmap, (sqr - oWidth) / 2, (sqr - oHeight) / 2, paint);
    return Bitmap.createScaledBitmap(background, width, height, false);
}
 
Example 11
Source File: LauncherShortcutUtils.java    From FreezeYou with Apache License 2.0 5 votes vote down vote up
/**
 * bm 和 icon 至少有一个不为 null,如均为非空则使用 bm
 *
 * @param title   Title
 * @param intent  Intent
 * @param icon    Icon
 * @param context Context
 * @param bm      Bitmap
 */
private static void requestCreateShortCutOldApi(String title, Intent intent, Drawable icon, Context context, Bitmap bm) {
    Intent addShortCut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    addShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    addShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    try {
        Bitmap bitmap;
        if (bm == null) {
            bitmap = getBitmapFromDrawable(icon);
        } else {
            bitmap = bm;
        }
        float size = context.getResources().getDimension(android.R.dimen.app_icon_size);
        if (size < 1) {
            size = 72;
        }
        if (bitmap.getHeight() > size) {
            Matrix matrix = new Matrix();
            float scaleWidth = (size) / bitmap.getWidth();
            float scaleHeight = (size) / bitmap.getHeight();
            matrix.postScale(scaleWidth, scaleHeight);
            addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON,
                    Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true));
            context.sendBroadcast(addShortCut);
        } else {
            addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
            context.sendBroadcast(addShortCut);
        }
        showToast(context, R.string.requested);
    } catch (Exception e) {
        e.printStackTrace();
        showToast(context, context.getString(R.string.requestFailed) + e.getMessage());
    }
}
 
Example 12
Source File: ImgUtil.java    From QiQuYing with Apache License 2.0 5 votes vote down vote up
/**
	 * 按照宽度的百分比压缩
	 * 
	 * @param srcBitmap
	 * @param newHeight
	 * @return
	 */
	public static Bitmap bitmapZoomByHeight(Bitmap srcBitmap, int newHeight) {
//		int srcWidth = srcBitmap.getWidth();
		int srcHeight = srcBitmap.getHeight();

		float scaleHeight = ((float) newHeight) / srcHeight;
//		float scaleWidth = 1;

		return bitmapZoomByScale(srcBitmap, scaleHeight, scaleHeight);
	}
 
Example 13
Source File: BitmapUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Crops a |bitmap| to a certain square |size|
 * @param bitmap The bitmap to crop.
 * @param size The size desired (width and height).
 * @return The resulting (square) bitmap.
 */
private static Bitmap cropToSquare(Bitmap bitmap, int size) {
    int x = 0;
    int y = 0;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == size && height == size) return bitmap;

    if (width > size) x = (width - size) / 2;
    if (height > size) y = (height - size) / 2;
    return Bitmap.createBitmap(bitmap, x, y, size, size);
}
 
Example 14
Source File: BitmapUtils.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 压缩一个Bitmap
 */
public static Bitmap getScaleBitmap(Bitmap bitmap, float scale) {
    // 1,600px × 900px
    if (bitmap != null && bitmap.getWidth() > 1600 && bitmap.getHeight() > 900) {
        float sx = 1600 / (float) bitmap.getWidth();
        float sy = 900 / (float) bitmap.getHeight();
        Bitmap result = Bitmap.createBitmap(1600, 900, Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        Matrix matrix = new Matrix();
        matrix.postScale(sx, sy);
        canvas.drawBitmap(bitmap, matrix, null);
        return result;
    }
    return bitmap;
}
 
Example 15
Source File: ImageReceiver.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public int getBitmapHeight() {
    if (currentImage instanceof AnimatedFileDrawable) {
        return orientation % 360 == 0 || orientation % 360 == 180 ? currentImage.getIntrinsicHeight() : currentImage.getIntrinsicWidth();
    } else if (staticThumb instanceof AnimatedFileDrawable) {
        return orientation % 360 == 0 || orientation % 360 == 180 ? staticThumb.getIntrinsicHeight() : staticThumb.getIntrinsicWidth();
    }
    Bitmap bitmap = getBitmap();
    if (bitmap == null) {
        if (staticThumb != null) {
            return staticThumb.getIntrinsicHeight();
        }
        return 1;
    }
    return orientation % 360 == 0 || orientation % 360 == 180 ? bitmap.getHeight() : bitmap.getWidth();
}
 
Example 16
Source File: ImageUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap getResizedBitmap(Bitmap image, int maxSize) {
    int width = image.getWidth();
    int height = image.getHeight();

    float bitmapRatio = (float) width / (float) height;
    if (bitmapRatio > 1) {
        width = maxSize;
        height = (int) (width / bitmapRatio);
    } else {
        height = maxSize;
        width = (int) (height * bitmapRatio);
    }
    return Bitmap.createScaledBitmap(image, width, height, true);
}
 
Example 17
Source File: BitmapText.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
protected void splitBy( Bitmap bitmap, int height, int color, String chars ) {
	
	autoUppercase = chars.equals( LATIN_UPPER );
	int length = chars.length();
	
	int width = bitmap.getWidth();
	float vHeight = (float)height / bitmap.getHeight();
	
	int pos;
	
spaceMeasuring:
	for (pos=0; pos <  width; pos++) {
		for (int j=0; j < height; j++) {
			if (bitmap.getPixel( pos, j ) != color) {
				break spaceMeasuring;
			}
		}
	}
	add( ' ', new RectF( 0, 0, (float)pos / width, vHeight ) );
	
	for (int i=0; i < length; i++) {
		
		char ch = chars.charAt( i );
		if (ch == ' ') {
			continue;
		} else {
			
			boolean found;
			int separator = pos;
			
			do {
				if (++separator >= width) {
					break;
				}
				found = true;
				for (int j=0; j < height; j++) {
					if (bitmap.getPixel( separator, j ) != color) {
						found = false;
						break;
					}
				}
			} while (!found);
			
			add( ch, new RectF( (float)pos / width, 0, (float)separator / width, vHeight ) );
			pos = separator + 1;
		}
	}
	
	lineHeight = baseLine = height( frames.get( chars.charAt( 0 ) ) );
}
 
Example 18
Source File: ScreenShotHelper.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Bitmap shotRecyclerView(RecyclerView view, int itemHeight) {
    RecyclerView.Adapter adapter = view.getAdapter();
    Bitmap bigBitmap = null;
    if (adapter != null) {
        int size = adapter.getItemCount();
        int height = 0;
        Paint paint = new Paint();
        int iHeight = 0;
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 8;
        LruCache<String, Bitmap> bitmaCache = new LruCache<>(cacheSize);
        for (int i = 0; i < size; i++) {
            RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i));
            adapter.onBindViewHolder(holder, i);
            holder.itemView.measure(
                    View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY),
                    View.MeasureSpec.makeMeasureSpec(itemHeight, View.MeasureSpec.EXACTLY));
            holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(),
                    holder.itemView.getMeasuredHeight());
            holder.itemView.setDrawingCacheEnabled(true);
            holder.itemView.buildDrawingCache();
            Bitmap drawingCache = holder.itemView.getDrawingCache();
            if (drawingCache != null) {
                bitmaCache.put(String.valueOf(i), drawingCache);
            }
            height += holder.itemView.getMeasuredHeight();
        }

        bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Config.ARGB_8888);
        Canvas bigCanvas = new Canvas(bigBitmap);
        Drawable lBackground = view.getBackground();
        if (lBackground instanceof ColorDrawable) {
            ColorDrawable lColorDrawable = (ColorDrawable) lBackground;
            int lColor = lColorDrawable.getColor();
            bigCanvas.drawColor(lColor);
        }

        for (int i = 0; i < size; i++) {
            Bitmap bitmap = bitmaCache.get(String.valueOf(i));
            bigCanvas.drawBitmap(bitmap, 0f, iHeight, paint);
            iHeight += bitmap.getHeight();
            bitmap.recycle();
        }
    }

    return bigBitmap;
}
 
Example 19
Source File: ImageHelper.java    From fanfouapp-opensource with Apache License 2.0 4 votes vote down vote up
/**
 * generate a blurred bitmap from given one
 * 
 * referenced: http://incubator.quasimondo.com/processing/superfastblur.pde
 * 
 * @param original
 * @param radius
 * @return
 */
public static Bitmap getBlurredBitmap(final Bitmap original,
        final int radius) {
    if (radius < 1) {
        return null;
    }

    final int width = original.getWidth();
    final int height = original.getHeight();
    final int wm = width - 1;
    final int hm = height - 1;
    final int wh = width * height;
    final int div = radius + radius + 1;
    final int r[] = new int[wh];
    final int g[] = new int[wh];
    final int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, p1, p2, yp, yi, yw;
    final int vmin[] = new int[Math.max(width, height)];
    final int vmax[] = new int[Math.max(width, height)];
    final int dv[] = new int[256 * div];
    for (i = 0; i < (256 * div); i++) {
        dv[i] = i / div;
    }

    final int[] blurredBitmap = new int[wh];
    original.getPixels(blurredBitmap, 0, width, 0, 0, width, height);

    yw = 0;
    yi = 0;

    for (y = 0; y < height; y++) {
        rsum = 0;
        gsum = 0;
        bsum = 0;
        for (i = -radius; i <= radius; i++) {
            p = blurredBitmap[yi + Math.min(wm, Math.max(i, 0))];
            rsum += (p & 0xff0000) >> 16;
            gsum += (p & 0x00ff00) >> 8;
            bsum += p & 0x0000ff;
        }
        for (x = 0; x < width; x++) {
            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            if (y == 0) {
                vmin[x] = Math.min(x + radius + 1, wm);
                vmax[x] = Math.max(x - radius, 0);
            }
            p1 = blurredBitmap[yw + vmin[x]];
            p2 = blurredBitmap[yw + vmax[x]];

            rsum += ((p1 & 0xff0000) - (p2 & 0xff0000)) >> 16;
            gsum += ((p1 & 0x00ff00) - (p2 & 0x00ff00)) >> 8;
            bsum += (p1 & 0x0000ff) - (p2 & 0x0000ff);
            yi++;
        }
        yw += width;
    }

    for (x = 0; x < width; x++) {
        rsum = gsum = bsum = 0;
        yp = -radius * width;
        for (i = -radius; i <= radius; i++) {
            yi = Math.max(0, yp) + x;
            rsum += r[yi];
            gsum += g[yi];
            bsum += b[yi];
            yp += width;
        }
        yi = x;
        for (y = 0; y < height; y++) {
            blurredBitmap[yi] = 0xff000000 | (dv[rsum] << 16)
                    | (dv[gsum] << 8) | dv[bsum];
            if (x == 0) {
                vmin[y] = Math.min(y + radius + 1, hm) * width;
                vmax[y] = Math.max(y - radius, 0) * width;
            }
            p1 = x + vmin[y];
            p2 = x + vmax[y];

            rsum += r[p1] - r[p2];
            gsum += g[p1] - g[p2];
            bsum += b[p1] - b[p2];

            yi += width;
        }
    }

    return Bitmap.createBitmap(blurredBitmap, width, height,
            Bitmap.Config.RGB_565);
}
 
Example 20
Source File: CloseableStaticBitmap.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return size in bytes of the underlying bitmap
 */
@Override
public int getSizeInBytes() {
  Bitmap bitmap = mBitmap;
  return (bitmap == null) ? 0 : bitmap.getHeight() * bitmap.getRowBytes();
}