AppWidget图象带圆角图象、圆角、AppWidget

由网友(要多霸气有多霸气)分享简介:所以,我用动态的动画,我要展示我的应用程序的主要布局了用户的各种视图中创建我的应用程序的图像。 So, I am dynamically creating an image within my app by animating various Views that I display to the user in t...

所以,我用动态的动画,我要展示我的应用程序的主要布局了用户的各种视图中创建我的应用程序的图像。

So, I am dynamically creating an image within my app by animating various Views that I display to the user in the main layout of my application.

目前我生成一个RelativeLayout的在我的场景,走布局的图像作为位图,然后保存位图到SD由通过URI的appwidget进行访问。

Currently I am generating my scene within a RelativeLayout, taking the image of the layout as a bitmap, then saving the bitmap to SD to be accessed by the appwidget via uri.

这是所有伟大的工作,但是...在attmept创建圆角为appwidget形象,我已经使用这两个片段,我发现here.

This is all working great, but... in an attmept to create rounded corners for the appwidget image, i've tried using these two snippets that I found here.

我的问题:

是,这种方法生成一个可绘制(其圆润的边角看起来完美的,如果显示为绘制),但我需要这些透明的角落导出为一个图像文件。所述drawToBitmap方法在CustomView下面,也会产生位图图像,但角落是充分和正方形。

is that this method generates a drawable (whose rounded corners look perfect if displayed as a drawable) but I need to export these transparent corners as an image file. The drawToBitmap method in CustomView below, does generate a bitmap image, but the corners are full and square.

/**
 * shows a bitmap as if it had rounded corners. based on :
 * http://rahulswackyworld.blogspot.co.il/2013/04/android-drawables-with-rounded_7.html
 */
public class RoundedCornersDrawable extends BitmapDrawable {

    private final BitmapShader bitmapShader;
    private final Paint p;
    private final RectF rect;
    private final float borderRadius;

    public RoundedCornersDrawable(final Resources resources, final Bitmap bitmap, final float     borderRadius) {
        super(resources, bitmap);
        bitmapShader = new BitmapShader(getBitmap(), Shader.TileMode.CLAMP,     Shader.TileMode.CLAMP);
        final Bitmap b = getBitmap();
        p = getPaint();
        p.setAntiAlias(true);
        p.setShader(bitmapShader);
        final int w = b.getWidth(), h = b.getHeight();
        rect = new RectF(0, 0, w, h);
        this.borderRadius = borderRadius < 0 ? 0.15f * Math.min(w, h) : borderRadius;
    }

    @Override
    public void draw(final Canvas canvas) {
        canvas.drawRoundRect(rect, borderRadius, borderRadius, p);
    }
}

public class CustomView extends ImageView {
    private FrameLayout mMainContainer;
    private boolean mIsDirty=false;

    // TODO for each change of views/content, set mIsDirty to true and call invalidate

    @Override
    protected void onDraw(final Canvas canvas) {
        if (mIsDirty) {
            mIsDirty = false;
            drawContent();
            return;
        }
        super.onDraw(canvas);
    }

    /**
     * draws the view's content to a bitmap. code based on :
     * https://p.xsw88.cn/allimgs/daicuo/20230903/5843.png.com");
bitmap.compress(CompressFormat.PNG, 100, stream);
stream.close();

但无济于事。这整个方法看似convoluded,但是这是我想出来的解决AppWidget的RemoteViews的限制。

but to no avail. This whole approach may seem convoluded, but this is what I've come up with to address the constraints of AppWidget's RemoteViews.

我的问题:

我怎么能采取这种RoundedCornersDrawable,并将其导出为能够正确描述它的美丽trasnparent角落?PNG文件

How can I take this RoundedCornersDrawable, and export it as a PNG file that properly depicts it's beautiful trasnparent corners?

在预先的帮助的感谢,我欢迎任何和不同的方法这个问题作为一个整体!

thanks in advance for the help, and I'm open to any and all suggestions on different approaches to the problem as a whole!

推荐答案

除了这个问题:

事实证明,我的AppWidget的大小裁剪图像   一直以来。裁剪它恰好能移开圆角,和   只是这么一点,以不被明显地裁剪。因此,对于任何人   那遇到这个问题......所有这些方法的工作,为这个   目的(只是别忘了让你的AppWidget大到足以见   的结果)。

'It turns out that the size of my AppWidget was clipping the image the whole time. Clipping it just enough to remove the rounded corners, and just so little as to not have been obviously clipped. So for anyone that comes across this question... all of these method's work for this purpose (just don't forget to make your AppWidget big enough to see the results).'

答:

我发现这是至关重要的通过CustomView.drawToBitMap()方法,将其导出到PNG文件之前也通过RoundedCornersDrawable。

I found it was critical to also pass the RoundedCornersDrawable through the CustomView.drawToBitMap() method before exporting it to the PNG file.

我希望这一切可以帮助别人在路上一天!

I hope this all helps someone down the road someday!

阅读全文

相关推荐

最新文章