Java Code Examples for android.graphics.Bitmap.Config#HARDWARE
The following examples show how to use
android.graphics.Bitmap.Config#HARDWARE .
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: TaskSnapshotLoader.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Loads a task from the disk. * <p> * Do not hold the window manager lock when calling this method, as we directly read data from * disk here, which might be slow. * * @param taskId The id of the task to load. * @param userId The id of the user the task belonged to. * @param reducedResolution Whether to load a reduced resolution version of the snapshot. * @return The loaded {@link TaskSnapshot} or {@code null} if it couldn't be loaded. */ TaskSnapshot loadTask(int taskId, int userId, boolean reducedResolution) { final File protoFile = mPersister.getProtoFile(taskId, userId); final File bitmapFile = reducedResolution ? mPersister.getReducedResolutionBitmapFile(taskId, userId) : mPersister.getBitmapFile(taskId, userId); if (bitmapFile == null || !protoFile.exists() || !bitmapFile.exists()) { return null; } try { final byte[] bytes = Files.readAllBytes(protoFile.toPath()); final TaskSnapshotProto proto = TaskSnapshotProto.parseFrom(bytes); final Options options = new Options(); options.inPreferredConfig = Config.HARDWARE; final Bitmap bitmap = BitmapFactory.decodeFile(bitmapFile.getPath(), options); if (bitmap == null) { Slog.w(TAG, "Failed to load bitmap: " + bitmapFile.getPath()); return null; } final GraphicBuffer buffer = bitmap.createGraphicBufferHandle(); if (buffer == null) { Slog.w(TAG, "Failed to retrieve gralloc buffer for bitmap: " + bitmapFile.getPath()); return null; } return new TaskSnapshot(buffer, proto.orientation, new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom), reducedResolution, reducedResolution ? REDUCED_SCALE : 1f, proto.isRealSnapshot, proto.windowingMode, proto.systemUiVisibility, proto.isTranslucent); } catch (IOException e) { Slog.w(TAG, "Unable to load task snapshot data for taskId=" + taskId); return null; } }
Example 2
Source File: SoftWareCanvas.java From sa-sdk-android with Apache License 2.0 | 5 votes |
private Bitmap drawOnSFCanvas(Bitmap bitmap) { if (VERSION.SDK_INT < 26 || bitmap.getConfig() != Config.HARDWARE) { return bitmap; } Bitmap sfBitmap = bitmap.copy(Config.ARGB_8888, false); this.bitmapWeakSet.add(sfBitmap); return sfBitmap; }
Example 3
Source File: SoftWareCanvas.java From sa-sdk-android with Apache License 2.0 | 5 votes |
private Paint replaceBitmapShader(Paint paint) { if (paint == null) { return null; } if (VERSION.SDK_INT >= 26 && (paint.getShader() instanceof BitmapShader)) { Paint saPaint = new Paint(paint); BitmapShader userBitmapShader = (BitmapShader) saPaint.getShader(); try { Field mBitmap = BitmapShader.class.getField("mBitmap"); mBitmap.setAccessible(true); if (((Bitmap) mBitmap.get(userBitmapShader)).getConfig() == Config.HARDWARE) { Field mTileX = BitmapShader.class.getDeclaredField("mTileX"); Field mTileY = BitmapShader.class.getDeclaredField("mTileY"); mTileX.setAccessible(true); mTileY.setAccessible(true); Bitmap sfBitmap = ((Bitmap) mBitmap.get(userBitmapShader)).copy(Config.ARGB_8888, false); this.bitmapWeakSet.add(sfBitmap); Constructor<BitmapShader> constructor = BitmapShader.class.getDeclaredConstructor(new Class[]{Bitmap.class, Integer.TYPE, Integer.TYPE}); constructor.setAccessible(true); BitmapShader bitmapShaderShader = (BitmapShader) constructor.newInstance(new Object[]{sfBitmap, mTileX.get(userBitmapShader), mTileY.get(userBitmapShader)}); Matrix matrix = new Matrix(); paint.getShader().getLocalMatrix(matrix); bitmapShaderShader.setLocalMatrix(matrix); saPaint.setShader(bitmapShaderShader); return saPaint; } } catch (Exception e) { SALog.i(TAG, e.toString()); } } return paint; }