2011-04-21 2 views
0

모든 이미지를 배경 이미지로 확대하고 싶습니다. 간단히 VerticalFieldManager를 만들고 페인트 메서드를 수정했습니다.메인 화면 배경으로 비트 맵 그리기. 이미지 스트레치 방법?

verticalFieldManager = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH 
          | VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR) { 
      public void paint(Graphics graphics) { 
        graphics.drawBitmap(0, 0, this.getWidth(), this.getHeight(), 
             backgroundBitmap, 0, 0); 
        super.paint(graphics); 
     } 

    }; 

ListField를 verticalFieldManager에 추가하고 스크롤하면 배경 이미지가 다시 그려지지 않습니다. 스크롤 할 때 배경을 다시 칠할 수 있습니까?

답변

2

Bitmap에서 EncodedImage을 만들거나 EncodedImage.getEncodedImageResource("res/bg.png")에서 EncodedImage을 직접 추출 할 수도 있습니다.

그런 다음 그것을 확장이 사용

public static EncodedImage resize(EncodedImage eImage, int toWidth, 
     int toHeight, boolean keepAspectRatio) { 

    int scaleX = Fixed32.div(
     Fixed32.toFP(eImage.getWidth()), 
     Fixed32.toFP(toWidth) 
    ); 

    int scaleY = Fixed32.div(
     Fixed32.toFP(eImage.getHeight()), 
     Fixed32.toFP(toHeight) 
    ); 

    if (keepAspectRatio) { 
     int scale = (scaleX > scaleY) ? scaleX : scaleY; 
     return eImage.scaleImage32(scale, scale); 
    } else { 
     return eImage.scaleImage32(scaleX, scaleY); 
    } 
} 

그런 다음 당신이 Graphics 개체의 EncodedImage을 그릴 수

graphics.drawImage(
    0, 0, 
    encodedImage.getScaledWidth(), ncodedImage.getScaledHeight(), 
    encodedImage, 0, 0, 0 
); 
+0

환상적인, 그것을 작동합니다. Arhimed 대단히 감사합니다. ListField 스크롤 문제에 대해 도와 주시겠습니까? 스크롤 할 때 배경 이미지도 스크롤됩니다. 스크롤 이벤트가 발생할 때 배경 이미지를 다시 그려야합니까? – redline

+0

오, 안돼. 이 코드를 사용할 때 listview의 마지막 항목 다음에 항상 공백이 있습니다. 그건 좋지 않다. – redline

+0

스크롤링 문제를 해결하려면 코드를 시험해야합니다. 죄송합니다. 지금 실험을 수행 할 수 없습니다. 시간이 부족합니다. 그러나 시도 할 생각은 현재 Ysroll (컨테이너의'Manager.getVerticalScroll()'사용)과 같은 수의 픽셀에서 BG 드로잉을위한 Y 좌표를 시작하는 것입니다. –