2012-11-26 4 views
0

제 생각에는 사소하지만 솔루션을 찾을 수 없습니다. 나는 WEB 페이지를 만드는 데 도움이 될 응용 프로그램을 만들려고하고 있으며 그래픽 요소를 화면에 적용 할 응용 프로그램을 만들고 싶습니다.리소스에서 캔버스에 새 비트 맵 만들기

나는 드로잉 가능한 PNG 이미지를 직사각형으로 만들어서 원하는 곳에 화면에 놓을 수는 있지만 아무런 문제가 없지만 새로운 그래픽/비트 맵을 만들 수는 없습니다.

meni DIV 또는 iFrame을 누르면 화면에 새 그래픽 개체를 어떻게 삽입 할 수 있습니까?

public class Objects extends View { 
    private float X; 
    private float Y; 
    private Paint myPaint; 
    final String C_DIV = "DIV"; 
    final String C_TABLE = "Table"; 
    final String C_IFRAME = "iFrame"; 
    final String C_LIST = "List"; 
    Canvas canvas; 
    Bitmap divimg = BitmapFactory.decodeResource(getResources(), R.drawable.div); 
    Bitmap iframeimg = BitmapFactory.decodeResource(getResources(), R.drawable.iframe); 
    Bitmap img = null; 
    String objectname = " "; 

    public Objects(Context context) { 
     super(context); 
     myPaint = new Paint(); 
    } 

    public void HTMLObjects(String object) { 
     Log.d(object, "see"); 
     if (object.equals(C_DIV)) { 
      myPaint.setColor(Color.GREEN); 
      img = Bitmap.createBitmap(divimg); 
      objectname = "DIV"; 
     } 
     if (object.equals(C_IFRAME)) { 
      myPaint.setColor(Color.BLUE); 
      img = Bitmap.createBitmap(iframeimg); 
      objectname = "iFrame"; 
     } 
    } 

    public boolean onTouchEvent(MotionEvent event) { 
     int action = event.getAction(); 
     switch (action) { 
      case MotionEvent.ACTION_DOWN: 
       X = (int) event.getX(); 
       Y = (int) event.getY(); 
       break; 
      case MotionEvent.ACTION_MOVE: 
      case MotionEvent.ACTION_UP: 
      case MotionEvent.ACTION_CANCEL: 
       X = (int) event.getX(); 
       Y = (int) event.getY(); 
       break; 
     } 
     return true; 
    } 

    public void onDraw(Canvas canvas) { 
     if (img != null) { 

      canvas.drawBitmap(img, X - 50, Y - 50, myPaint); 
      canvas.drawText(objectname, X, Y - 50, myPaint); 
     } 
     invalidate(); 
    } 
} 

내가

ob.HTMLObjects((String) item.getTitle()); 

로 활동 작업 공간에서 전화, 그리고 난 메뉴를 누르면 정보를 보낸다 클래스입니다.

DIV 또는 iFrame을 눌렀을 때 새로운/다른 오브젝트/비트 맵을 만드는 방법을 모르겠습니다.

+2

당신이'BitmapFactory.decodeResource'를 사용하여 리소스에서'Bitmap'를 만드는 방법을 알고있다. 나는 네가 원하는 것을 완전히 이해하지 못한다. –

+0

비트 맵 복사본을 만들고 싶습니다. meni DIV를 누르면 새로운 비트 맵을 원한다. 오래된 비트 맵은 내가 살았던 위치에 머무를 것이고 나는 새로운 위치에 놓을 새로운 비트 맵을 만들고 싶다. 미안 해요. –

+0

이미 코드를 작성한 것으로 보입니다. 그것은 작동하지 않습니까? –

답변

3

이러한 버전을 사용해보십시오. 나는 따라 목록과 x, y, img, objectname를 대체 것 같다

public class Objects extends View { 
    private Paint myPaint; 
    public final String C_DIV="DIV"; 
    public final String C_TABLE="Table"; 
    public final String C_IFRAME="iFrame"; 
    public final String C_LIST="List"; 
    private Canvas canvas; 
    private Bitmap divimg= BitmapFactory.decodeResource(getResources(), R.drawable.div); 
    private Bitmap iframeimg=BitmapFactory.decodeResource(getResources(), R.drawable.iframe); 
    private List<Bitmap> images; 
    private List<Float> xs; 
    private List<Float> ys; 
    private List<String> objectNames; 

    public Objects(Context context) { 
     super(context); 
     myPaint = new Paint(); 
     images = new ArrayList<Bitmap>(); 
     xs = new ArrayList<Float>(); 
     ys = new ArrayList<Float>(); 
     objectNames = new ArrayList<String>(); 
    } 

    public void HTMLObjects(String object){ 
     Log.d(object, "see"); 
     if (object.equals(C_DIV)) { 
      myPaint.setColor(Color.GREEN); 
      images.add(Bitmap.createBitmap(divimg)); 
      objectNames.add("DIV"); 
      xs.add(0F); 
      ys.add(0F); 
     } 
     if (object.equals(C_IFRAME)){ 
      myPaint.setColor(Color.BLUE); 
      images.add(Bitmap.createBitmap(iframeimg)); 
      objectNames.add("iFrame"); 
      xs.add(0F); 
      ys.add(0F); 
     } 
    } 
    public boolean onTouchEvent(MotionEvent event) { 
     int action=event.getAction(); 
     if (xs.isEmpty()) { 
      return true; 
     } 
     int pos = xs.size() - 1; 
     switch(action) { 
      case MotionEvent.ACTION_DOWN: 
       xs.set(pos, event.getX()); 
       ys.set(pos, event.getY()); 
       break; 
      case MotionEvent.ACTION_MOVE: 
      case MotionEvent.ACTION_UP: 
      case MotionEvent.ACTION_CANCEL: 
       xs.set(pos, event.getX()); 
       ys.set(pos, event.getY()); 
       break; 
     } 
     return true; 
    } 
    public void onDraw(Canvas canvas){ 
     for (int i = 0; i < images.size(); i++) { 
      float x = xs.get(i); 
      float y = ys.get(i); 
      canvas.drawBitmap(images.get(i), x-50, y-50, myPaint); 
      canvas.drawText(objectNames.get(i), x, y-50, myPaint); 
     } 
     invalidate(); 
    } 
} 
+0

정말 고마워요. 내게 곰 : –

+0

@ IstarEnki 그것이 당신을 도운다면 대답을 수락하십시오 :) –

관련 문제