@Nullable private static Value createScaledBitmap( @NotNull EvaluationContextImpl context, @NotNull ObjectReference bitmap, @NotNull Dimension currentDimensions) throws EvaluateException { DebugProcessImpl debugProcess = context.getDebugProcess(); Method createScaledBitmapMethod = DebuggerUtils.findMethod( bitmap.referenceType(), "createScaledBitmap", "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;"); if (createScaledBitmapMethod == null) { return null; } double s = Math.max(currentDimensions.getHeight(), currentDimensions.getWidth()) / MAX_DIMENSION; VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy(); Value dstWidth = DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getWidth() / s)); Value dstHeight = DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getHeight() / s)); Value filter = DebuggerUtilsEx.createValue(vm, "boolean", Boolean.FALSE); return debugProcess.invokeMethod( context, bitmap, createScaledBitmapMethod, Arrays.asList(bitmap, dstWidth, dstHeight, filter)); }
@Nullable private static Value getBitmapConfig(EvaluationContextImpl context, ObjectReference bitmap) throws EvaluateException { DebugProcessImpl debugProcess = context.getDebugProcess(); Method getConfig = DebuggerUtils.findMethod( bitmap.referenceType(), "getConfig", "()Landroid/graphics/Bitmap$Config;"); if (getConfig == null) { return null; } return debugProcess.invokeMethod(context, bitmap, getConfig, Collections.emptyList()); }
@Nullable private static List<Value> copyToBuffer( EvaluationContextImpl evaluationContext, ObjectReference bitmap, Dimension size) throws EvaluateException { DebugProcessImpl debugProcess = evaluationContext.getDebugProcess(); VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy(); List<ReferenceType> classes = virtualMachineProxy.classesByName("byte[]"); if (classes.size() != 1 || !(classes.get(0) instanceof ArrayType)) { return null; } ArrayType byteArrayType = (ArrayType) classes.get(0); classes = virtualMachineProxy.classesByName("java.nio.ByteBuffer"); if (classes.size() != 1 || !(classes.get(0) instanceof ClassType)) { return null; } ClassType byteBufferType = (ClassType) classes.get(0); Method wrapMethod = DebuggerUtils.findMethod(byteBufferType, "wrap", "([B)Ljava/nio/ByteBuffer;"); if (wrapMethod == null) { return null; } ArrayReference byteArray = byteArrayType.newInstance(size.width * size.height * 4); Value byteBufferRef = debugProcess.invokeMethod( evaluationContext, byteBufferType, wrapMethod, ImmutableList.of(byteArray)); Method copyToBufferMethod = DebuggerUtils.findMethod( bitmap.referenceType(), "copyPixelsToBuffer", "(Ljava/nio/Buffer;)V"); if (copyToBufferMethod == null) { return null; } debugProcess.invokeMethod( evaluationContext, bitmap, copyToBufferMethod, ImmutableList.of(byteBufferRef)); return byteArray.getValues(); }