从SVG Url资源获取位图

时间:2015-10-01 13:47:19

标签: android svg bitmap android-widget android-glide

我正在尝试使用Glide从URL获取SVG资源,但我不知道如何获取Bitmap对象而不是将其加载到View中。
原因是我需要在Widget上加载一些SVG文件。

我使用了这个例子:https://stackoverflow.com/a/30938082/3346625

更新1: 设置GenericRequestBuilder

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char **argv) {

if (argc != 4) {
    printf("Error:  Need 3 integer arguments\n");
    exit(1);
}

pid_t pid, pid1, pid2;
int returnstatus, returnstatus1, returnstatus2;

pid = fork();
// Child 1: Sum
if (pid == 0) {
    printf("Child 1 PID = %d\n", getpid());

    int a, b, c;
    a = atoi(argv[1]);
    b = atoi(argv[2]);
    c = atoi(argv[3]);
    printf("Sum of integers = %d\n", a+b+c);
}
else {
    // wait(NULL);  works, but best practice is to get return code
    waitpid(pid, &returnstatus, 0);

    pid1 = fork();

    // Child 2: Product
    if (pid1 == 0) {
        printf("Child 2 PID = %d\n", getpid());

        int a, b, c;
        a = atoi(argv[1]);
        b = atoi(argv[2]);
        c = atoi(argv[3]);
        printf("Product of integers = %d\n", a*b*c);
    }
    else {
        waitpid(pid1, &returnstatus1, 0);

        pid2 = fork();

        // Child 3: Sum of squares
        if (pid2 == 0) {
            printf("Child 3 PID = %d\n", getpid());

            int a, b, c;
            a = atoi(argv[1]);
            b = atoi(argv[2]);
            c = atoi(argv[3]);
            printf("Sum of squares of integers = %d\n", (a*a)+(b*b)+(c*c));
        }
        else {
            waitpid(pid2, &returnstatus2, 0);

            printf("Parent PID = %d\n", getpid());
        }
    }

}



return 0;
}
  • 我必须使用Runnable作为requestBuilder.into需要在主线程上运行。

如何获取Bitmap以便稍后将其与RemoteView一起使用?

1 个答案:

答案 0 :(得分:1)

试试这个:

.transcode(new SvgBitmapTranscoder(), Bitmap.class)

.into(new SimpleTarget<Bitmap>(sizeW, sizeH) {
    @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
        // update RemoteViews with resource
    }
})
如果有SvgBitmapTranscoder方法,

svg.renderToBitmap()应该相当简单。

相关问题