好吧也许我在这里遗漏了一些东西,但我被困了好几个小时.我创建了一个应用程序,用户在图片上绘制尺寸线.现在我想绘制一些选择点,表明该行已被选中.这些点是一个特定的位图,必须位于该行的末尾(箭头后)并根据箭头旋转.我创建了一个扩展View的类DrawSelectionPoint,我可以使用以下内容旋转位图:
selectionPoint = BitmapFactory.decodeResource(context.getResources(),
R.drawable.selectionpoint);
Matrix matrix = new Matrix();
matrix.postRotate((float)Math.toDegrees(angle));
canvas.drawBitmap(selectionPoint, matrix, null);
Run Code Online (Sandbox Code Playgroud)
(其中angle是直线的角度)这样我的位图按照我想要的方式旋转,但是它绘制在点0,0(屏幕的左上角).
如果我使用类似的东西
canvas.save();
canvas.rotate();
canvas.drawBitmap(selectionPoint, x, y, null);
canvas.restore();
Run Code Online (Sandbox Code Playgroud)
然后我发现在我想要的确切位置绘制位图太难了(因为我在旋转的画布上绘制,然后我将其旋转回来).我尝试了一些欧几里德旋转变换,但我没有运气.
有没有办法应用矩阵旋转,并给出我需要绘制位图的点?先感谢您!
我是 Rust 新手,我正在尝试了解更多有关生命周期的知识。我遇到了以下代码,它无法编译(Playground):
struct Person<'a, 'b> {
name: &'a str,
email: &'b str,
}
fn main() {
let my_name: String = String::from("John Doe");
let me: Person;
{
let my_email: String = String::from("john@example.com");
me = Person {
name: &my_name,
email: &my_email,
};
}
println!("My name is {}.", me.name);
}
Run Code Online (Sandbox Code Playgroud)
请注意 的定义中使用了两个不同的生命周期参数Person。
这是编译错误:
error[E0597]: `my_email` does not live long enough
--> src/main.rs:15:20
|
15 | email: &my_email,
| ^^^^^^^^^ borrowed value does not live long enough
16 | …Run Code Online (Sandbox Code Playgroud)