0

我有一个可绘制的。在写入可绘制文本之前,我想绕其中心旋转

drawable= this.getResources().getDrawable(R.drawable.image);

final int IMAGE_WIDTH = drawable.getIntrinsicWidth();
final int IMAGE_HEIGHT = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap.createBitmap(IMAGE_WIDTH, 
                                      IMAGE_HEIGHT, 
                                      Bitmap.Config.ARGB_8888);
Canvas imageCanvas = new Canvas(bitmap); 

Paint imagePaint = new Paint();
imagePaint.setTextAlign(Align.CENTER);
imagePaint.setTextSize(16f);

drawable.draw(imageCanvas);

imageCanvas.drawText("", 
                     IMAGE_WIDTH / 2, 
                     (IMAGE_HEIGHT - imagePaint.ascent()) / 2, 
                     imagePaint);                   

LayerDrawable finalImage = new LayerDrawable(
     new Drawable[]{drawable, new BitmapDrawable(bitmap)}); 
4

3 回答 3

0

您可以使用矩阵来完成所有旋转游戏,然后将其设置到您的画布上。

于 2013-05-23T14:46:33.057 回答
0

最好的方法是查看动画。 http://developer.android.com/guide/topics/resources/animation-resource.html#Tween

于 2013-05-23T14:53:03.863 回答
0

我找到了解决方案

Bitmap  bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.image);                      
                    final int IMAGE_WIDTH = drawable.getIntrinsicWidth();
                    final int IMAGE_HEIGHT = drawable.getIntrinsicHeight();                                         
                    Matrix matrix = new Matrix();
                    matrix.postRotate(rotate);
                    Bitmap resizedBitmap = Bitmap.createBitmap(bmpOriginal, 0, 0,width, height, matrix, true);
                    Canvas imageCanvas = new Canvas(resizedBitmap); 
                    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

                    Paint imagePaint = new Paint();
                    imagePaint.setTextAlign(Align.CENTER);
                    imagePaint.setTextSize(14f);

                    bmd.draw(imageCanvas);

                    imageCanvas.drawText("Text", 
                                             IMAGE_WIDTH / 2, 
                                             (IMAGE_HEIGHT - imagePaint.ascent()) / 2, 
                                             imagePaint);                   

                    LayerDrawable finalImage = new LayerDrawable(
                         new Drawable[]{bmd, new BitmapDrawable(resizedBitmap)}); 
于 2013-05-24T13:06:12.993 回答