有另一种方式来绘制一个对象在Android的画布上?
里面得出这样的code()不工作:
BMP位= BitmapFactory.de codeResource(getResources(),R.drawable.pushpin);
canvas.drawBitmap(BMP,screenPts.x,screenPts.y-50,空);
嗯,事实上,它的工作对我的第一code,但是当我转移至其它类叫做MarkOverlay,它不工作了。
markerOverlay =新MarkerOverlay(getApplicationContext(),P);
listOfOverlays.add(markerOverlay);
我要传递给MarkerOverlay什么参数,使这个code的工作?该错误是在getResources某处()。
仅供参考,canvas.drawOval完美地工作,但我真的想画的图像不是一个椭圆形。 :)
解决方案 包com.canvas;
进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.Canvas;
进口android.graphics.Color;
进口android.graphics.Paint;
进口android.view.View;
公共类Keypaint扩展视图{
涂料P;
@覆盖
保护无效的OnDraw(帆布油画){
super.onDraw(画布);
P =新的油漆();
位图B = BitmapFactory.de codeResource(getResources(),R.drawable.icon);
p.setColor(Color.RED);
canvas.drawBitmap(二,0,0,p)的;
}
公共Keypaint(上下文的背景下){
超(上下文);
}
}
Is there another way to draw an object on a canvas in android?
This code inside draw() doesn't work:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
Well actually, it's working on my 1st code but when I've transfered this to another class called MarkOverlay, it's not working anymore.
markerOverlay = new MarkerOverlay(getApplicationContext(), p);
listOfOverlays.add(markerOverlay);
What parameter should I pass to MarkerOverlay to make this code work? The error is somewhere in getResources().
FYI, canvas.drawOval is perfectly working but I really want to draw an Image not an Oval. :)
解决方案package com.canvas;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class Keypaint extends View {
Paint p;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
p=new Paint();
Bitmap b=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
p.setColor(Color.RED);
canvas.drawBitmap(b, 0, 0, p);
}
public Keypaint(Context context) {
super(context);
}
}