English 中文(简体)
Adroid - 油漆旋转位图到画布上的具体位置
原标题:Android - paint rotated bitmap into a specific location on canvas

Ok 可能我错过了这里的东西, 但我被卡住了几个小时 。 我制作了一个应用程序, 用户用这个程序在图片上绘制一个维度线。 现在我要同时绘制一些选择点, 显示线被选中。 这些点是一个特定的位图, 必须在线的末尾( 箭头后面) 并按箭头旋转 。 我创建了一个班级 DrawSectionPoint, 扩展视图, 我可以以类似的方式旋转位图 :

selectionPoint = BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.selectionpoint);
Matrix matrix = new Matrix();
        matrix.postRotate((float)Math.toDegrees(angle));        
canvas.drawBitmap(selectionPoint, matrix, null);

(角度是线的角) 这样我的位图就按照我想要的方式旋转, 但是它画在0,0点(屏幕左上方)上。

如果我用那种东西

canvas.save();

canvas.rotate();

canvas.drawBitmap(selectionPoint, x, y, null);

canvas.restore(); 

然后,我发现很难在我想要的确切位置绘制位图(因为我画的是旋转的画布,然后我再转回去 ) 。 我尝试了一些欧几里得旋转的转换,但我没有运气。

是否有某种方法可以应用矩阵旋转, 并给出需要绘制位图的点数? 提前感谢!!

最佳回答

假设您想要绘制位图, 位图的 < em> 中心 将位于( px, pp) 画布坐标处。 请使用成员变量

Matrix matrix = new Matrix();

和你们所行的善功,

matrix.reset();
matrix.postTranslate(-bitmap.getWidth() / 2, -bitmap.getHeight() / 2); // Centers image
matrix.postRotate(angle);
matrix.postTranslate(px, py);
canvas.drawBitmap(bitmap, matrix, null);
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签