Java Code Examples for android.graphics.Bitmap#Config
The following examples show how to use
android.graphics.Bitmap#Config .
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: BitmapHelper.java From 365browser with Apache License 2.0 | 6 votes |
/** * Provides a matching integer constant for the Bitmap.Config value passed. * * @param bitmapConfig The Bitmap Configuration value. * @return Matching integer constant for the Bitmap.Config value passed. */ @CalledByNative private static int getBitmapFormatForConfig(Bitmap.Config bitmapConfig) { switch (bitmapConfig) { case ALPHA_8: return BitmapFormat.ALPHA_8; case ARGB_4444: return BitmapFormat.ARGB_4444; case ARGB_8888: return BitmapFormat.ARGB_8888; case RGB_565: return BitmapFormat.RGB_565; default: return BitmapFormat.NO_CONFIG; } }
Example 2
Source File: ACache.java From RxEasyHttp with Apache License 2.0 | 6 votes |
private static Bitmap drawable2Bitmap(Drawable drawable) { if (drawable == null) { return null; } int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap(w, h, config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
Example 3
Source File: BitmapManager.java From document-viewer with GNU General Public License v3.0 | 5 votes |
public static int getPixelSizeInBytes(final Bitmap.Config config) { switch (config) { case ALPHA_8: return 1; case ARGB_4444: case RGB_565: return 2; case ARGB_8888: default: return 4; } }
Example 4
Source File: Utils.java From BrokenView with MIT License | 5 votes |
static Bitmap createBitmapSafely(int width, int height, Bitmap.Config config, int retryCount) { while(retryCount-- > 0) { try { return Bitmap.createBitmap(width, height, config); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); } } return null; }
Example 5
Source File: AnimatedFactoryV2Impl.java From fresco with MIT License | 5 votes |
@Override public ImageDecoder getGifDecoder(final Bitmap.Config bitmapConfig) { return new ImageDecoder() { @Override public CloseableImage decode( EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) { return getAnimatedImageFactory().decodeGif(encodedImage, options, bitmapConfig); } }; }
Example 6
Source File: ThemePreference.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
public static void createCircularPreferenceBitmap(Boolean isImage, Preference preference, ImageView imageView, Context context, int color) { Bitmap.Config conf = Bitmap.Config.ARGB_8888; int dimen = (int) context.getResources().getDimension(android.R.dimen.app_icon_size); Bitmap bmp = Bitmap.createBitmap(dimen, dimen, conf); if (isImage) { imageView.setBackground(createRoundedBitmapDrawable(bmp, color, context.getResources())); } else { preference.setIcon(createRoundedBitmapDrawable(bmp, color, context.getResources())); } }
Example 7
Source File: ImageRequest.java From NoHttp with Apache License 2.0 | 5 votes |
public ImageRequest(String url, RequestMethod requestMethod, int maxWidth, int maxHeight, Bitmap.Config decodeConfig, ImageView.ScaleType scaleType) { super(url, requestMethod); this.mMaxWidth = maxWidth; this.mMaxHeight = maxHeight; this.mDecodeConfig = decodeConfig; this.mScaleType = scaleType; setAccept("image/*"); }
Example 8
Source File: AbstractBitmapRef.java From document-viewer with GNU General Public License v3.0 | 5 votes |
AbstractBitmapRef(final Bitmap.Config config, boolean hasAlpha, int width, int height, final long generation) { this.config = config; this.hasAlpha = hasAlpha; this.width = width; this.height = height; this.size = BitmapManager.getBitmapBufferSize(width, height, config); this.gen = generation; }
Example 9
Source File: SvgUtils.java From SvgGlidePlugins with Apache License 2.0 | 5 votes |
@NonNull public static Bitmap toBitmap( @NonNull SVG svg, @NonNull BitmapProvider provider, @NonNull Bitmap.Config config ) { int outImageWidth = Math.round(svg.getDocumentWidth()); int outImageHeight = Math.round(svg.getDocumentHeight()); Bitmap bitmap = provider.get(outImageWidth, outImageHeight, config); Canvas canvas = new Canvas(bitmap); svg.renderToCanvas(canvas); return bitmap; }
Example 10
Source File: DefaultDecoder.java From fresco with MIT License | 4 votes |
@Override public CloseableReference<Bitmap> decodeFromEncodedImage( EncodedImage encodedImage, Bitmap.Config bitmapConfig, @Nullable Rect regionToDecode) { return decodeFromEncodedImageWithColorSpace(encodedImage, bitmapConfig, regionToDecode, null); }
Example 11
Source File: BitmapPoolAdapter.java From giffun with Apache License 2.0 | 4 votes |
@Override public Bitmap get(int width, int height, Bitmap.Config config) { return null; }
Example 12
Source File: Nv21Image.java From easyrs with MIT License | 4 votes |
/** * Converts an android Bitmap image to NV21 format. If the image has odd dimensions the * conversion process will round down each dimension to its closest even integer. * @param dstArray is an optional byte array to receive the converted NV21 data. It * must be (1.5 * number_of_pixels) bytes long. If null is passed, * a new byte array will be created and returned. */ public static Nv21Image bitmapToNV21(RenderScript rs, Bitmap bitmap, byte[] dstArray) { long startTime = System.currentTimeMillis(); Bitmap croppedBitmap = bitmap; if (bitmap.getWidth() % 2 > 0 || bitmap.getHeight() % 2 > 0) { croppedBitmap = Bitmap.createBitmap(bitmap, 0, 0, (bitmap.getWidth() / 2) * 2, (bitmap.getHeight() / 2) * 2); } Bitmap yuvImage = ColorMatrix.applyMatrix(rs, croppedBitmap, ColorMatrixParams.rgbToNv21Matrix(), new Float4(0.0f, 0.5f, 0.5f, 0.0f)); RSToolboxContext bitmapRSContext = RSToolboxContext.createFromBitmap(rs, yuvImage); ScriptC_channel channelScript = new ScriptC_channel(bitmapRSContext.rs); Type outType = Type.createXY(bitmapRSContext.rs, Element.U8(bitmapRSContext.rs), yuvImage.getWidth(), yuvImage.getHeight()); Allocation aout = Allocation.createTyped(bitmapRSContext.rs, outType); channelScript.forEach_channelR(bitmapRSContext.ain, aout); int size = croppedBitmap.getWidth() * croppedBitmap.getHeight(); byte[] yByteArray; if (dstArray == null) yByteArray = new byte[size + size / 2]; else yByteArray = dstArray; aout.copyTo(yByteArray); Bitmap.Config config = yuvImage.getConfig(); Bitmap resizedBmp = Bitmap.createBitmap(yuvImage.getWidth()/2, yuvImage.getHeight()/2, config); Type resizeoutType = Type.createXY(bitmapRSContext.rs, bitmapRSContext.ain.getElement(), yuvImage.getWidth()/2, yuvImage.getHeight()/2); Allocation resizeaout = Allocation.createTyped(bitmapRSContext.rs, resizeoutType); ScriptIntrinsicResize resizeScript = ScriptIntrinsicResize.create(bitmapRSContext.rs); resizeScript.setInput(bitmapRSContext.ain); resizeScript.forEach_bicubic(resizeaout); resizeaout.copyTo(resizedBmp); Allocation resizedIn = Allocation.createFromBitmap(bitmapRSContext.rs, resizedBmp); ScriptC_uvencode encodeScript = new ScriptC_uvencode(bitmapRSContext.rs); Type uvtype = Type.createX(bitmapRSContext.rs, Element.U8(bitmapRSContext.rs), size / 2); Allocation uvAllocation = Allocation.createTyped(bitmapRSContext.rs, uvtype); encodeScript.set_width(yuvImage.getWidth()); encodeScript.set_height(yuvImage.getHeight()); encodeScript.set_gOut(uvAllocation); encodeScript.forEach_root(resizedIn); byte[] uvByteArray = new byte[size / 2]; uvAllocation.copyTo(uvByteArray); System.arraycopy(uvByteArray, 0, yByteArray, size, uvByteArray.length); Log.d("NV21", "Conversion to NV21: " + (System.currentTimeMillis() - startTime) + "ms"); return new Nv21Image(yByteArray, yuvImage.getWidth(), yuvImage.getHeight()); }
Example 13
Source File: AttributeStrategy.java From giffun with Apache License 2.0 | 4 votes |
@Override public Bitmap get(int width, int height, Bitmap.Config config) { final Key key = keyPool.get(width, height, config); return groupedMap.get(key); }
Example 14
Source File: BitmapUtils.java From android-open-project-demo with Apache License 2.0 | 4 votes |
public BitmapUtils configDefaultBitmapConfig(Bitmap.Config config) { defaultDisplayConfig.setBitmapConfig(config); return this; }
Example 15
Source File: SketchGifDrawableImpl.java From sketch with Apache License 2.0 | 4 votes |
@Override public Bitmap.Config getBitmapConfig() { return mBuffer != null ? mBuffer.getConfig() : null; }
Example 16
Source File: AnimatedFactory.java From fresco with MIT License | 4 votes |
@Nullable ImageDecoder getGifDecoder(Bitmap.Config config);
Example 17
Source File: CameraPainter.java From ssj with GNU General Public License v3.0 | 4 votes |
/** * @param stream_in Stream[] */ @Override public final void enter(Stream[] stream_in) throws SSJFatalException { if (stream_in.length != 1) { Log.e("Stream count not supported"); return; } if (stream_in[0].type != Cons.Type.IMAGE) { Log.e("Stream type not supported"); return; } synchronized (this) { if (surfaceViewInner == null) { //wait for surfaceView creation try { this.wait(); } catch (InterruptedException ex) { ex.printStackTrace(); } } } ImageStream in = (ImageStream)stream_in[0]; surfaceHolder = surfaceViewInner.getHolder(); iaRgbData = new int[in.width * in.height]; //set bitmap Bitmap.Config conf = Bitmap.Config.ARGB_8888; bitmap = Bitmap.createBitmap(in.width, in.height, conf); //register listener if (_evchannel_in != null && _evchannel_in.size() != 0) { for (EventChannel ch : _evchannel_in) { ch.addEventListener(this); } } if (options.showBestMatch.get()) { interiorPaint = new Paint(); interiorPaint.setTextSize(textSize); interiorPaint.setColor(Color.WHITE); interiorPaint.setStyle(Paint.Style.FILL); interiorPaint.setAntiAlias(false); interiorPaint.setAlpha(255); exteriorPaint = new Paint(); exteriorPaint.setTextSize(textSize); exteriorPaint.setColor(Color.BLACK); exteriorPaint.setStyle(Paint.Style.FILL_AND_STROKE); exteriorPaint.setStrokeWidth(textSize / 8); exteriorPaint.setAntiAlias(false); exteriorPaint.setAlpha(255); } }
Example 18
Source File: ImageUtils.java From FireFiles with Apache License 2.0 | 4 votes |
public static Bitmap getVideoThumbnail(String path, int mMaxWidth, int mMaxHeight){ Bitmap.Config mDecodeConfig = Bitmap.Config.RGB_565; ImageView.ScaleType mScaleType = ImageView.ScaleType.CENTER_CROP; File bitmapFile = new File(path); Bitmap bitmap = null; if (!bitmapFile.exists() || !bitmapFile.isFile()) { return bitmap; } BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); decodeOptions.inInputShareable = true; decodeOptions.inPurgeable = true; decodeOptions.inPreferredConfig = mDecodeConfig; if (mMaxWidth == 0 && mMaxHeight == 0) { bitmap = getVideoFrame(bitmapFile.getAbsolutePath()); } else { // If we have to resize this image, first get the natural bounds. decodeOptions.inJustDecodeBounds = true; //BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions); int actualWidth = decodeOptions.outWidth; int actualHeight = decodeOptions.outHeight; // Then compute the dimensions we would ideally like to decode to. int desiredWidth = getResizedDimension(mMaxWidth, mMaxHeight, actualWidth, actualHeight, mScaleType); int desiredHeight = getResizedDimension(mMaxHeight, mMaxWidth, actualHeight, actualWidth, mScaleType); // Decode to the nearest power of two scaling factor. decodeOptions.inJustDecodeBounds = false; decodeOptions.inSampleSize = ImageUtils.findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight); Bitmap tempBitmap = getVideoFrame(bitmapFile.getAbsolutePath()); // 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 19
Source File: PlatformDecoder.java From fresco with MIT License | 2 votes |
/** * Creates a bitmap from encoded JPEG bytes. Supports a partial JPEG image. In addition, a region * to decode can be supplied in order to minimize memory usage. NOTE: Not all platform decoders * necessarily support supplying specific regions. * * <p>Note: This needs to be kept because of dependencies issues. * * @param encodedImage the reference to the encoded image with the reference to the encoded bytes * @param bitmapConfig the {@link android.graphics.Bitmap.Config} used to create the decoded * Bitmap * @param regionToDecode optional image region to decode or null to decode the whole image. * @param length the number of encoded bytes in the buffer * @return the bitmap * @throws TooManyBitmapsException if the pool is full * @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated */ CloseableReference<Bitmap> decodeJPEGFromEncodedImage( EncodedImage encodedImage, Bitmap.Config bitmapConfig, @Nullable Rect regionToDecode, int length);
Example 20
Source File: CompatDecoderFactory.java From pdfview-android with Apache License 2.0 | 2 votes |
/** * Construct a factory for the given class. This must have a constructor that accepts a {@link Bitmap.Config} instance. * @param clazz a class that implements {@link ImageDecoder} or {@link ImageRegionDecoder}. * @param bitmapConfig bitmap configuration to be used when loading images. */ public CompatDecoderFactory(@NonNull Class<? extends T> clazz, Bitmap.Config bitmapConfig) { this.clazz = clazz; this.bitmapConfig = bitmapConfig; }