Android的drawbitmap绘制图片的位置与缩放问题
绘图时使用canvas.drawBitmap(bitmap,left,top,paint);它是从坐标的左上角开始画的,怎么使其从中间点开始画,然后图片怎么按照屏幕大小进...
绘图时使用canvas.drawBitmap(bitmap, left, top, paint);它是从坐标的左上角开始画的,怎么使其从中间点开始画,然后图片怎么按照屏幕大小进行缩放?或是给出另外的绘图方案都可以,谢谢啦~!
展开
展开全部
MainActivity.java
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new MainLayout(this));
}
}
class MainLayout extends RelativeLayout
{
public MainLayout(Context context)
{
super(context);
setWillNotDraw(false);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
bitmap = Bitmap.createScaledBitmap(bitmap, 854, 480, true);
canvas.drawBitmap
(
bitmap,
null,
new Rect(0, 0, 854, 480),
null
);
}
}
希望能够帮助到你,望采纳!
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new MainLayout(this));
}
}
class MainLayout extends RelativeLayout
{
public MainLayout(Context context)
{
super(context);
setWillNotDraw(false);
}
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
bitmap = Bitmap.createScaledBitmap(bitmap, 854, 480, true);
canvas.drawBitmap
(
bitmap,
null,
new Rect(0, 0, 854, 480),
null
);
}
}
希望能够帮助到你,望采纳!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询