2011-11-23 6 views
0

LWUIT 양식의 배경 이미지로 png 이미지를 만들고 싶습니다. 문제는 이미지가 변경되었음을 의미합니다. 이미지의 모양이 배경의 이미지로 설정된 후에 이미지에 얼룩이 있습니다. 다음 코드는 다음과 같습니다PNG LWUIT 양식의 배경 이미지로 설정하면 이미지가 심하게 오염됩니다.

public class DetailPhotoClient extends Form implements ActionListener { 

    private Command options, delete, back, annuler, ok; 
    private GaleriePhotos backForm; 
    private FileConnection fcFile; 
    private Image sourceImage, fullImage; 
    private InputStream is; 
    private PopupMenu popup; 

    public DetailPhotoClient(GaleriePhotos prevForm, String absolutePathphotoName) 
    { 
     super(); 
     back = new Command("Retour"); 
     options = new Command("Options"); 
     this.addCommand(back); 
     this.addCommand(options); 
     this.addCommandListener(this); 

     delete = new Command("Supprimer"); 
     annuler = new Command("Annuler"); 
     ok = new Command("Ok"); 

     backForm = prevForm; 

     try { 
      fcFile = (FileConnection) Connector.open(absolutePathphotoName, Connector.READ); 
      is = fcFile.openInputStream(); 
      sourceImage = Image.createImage(is); 
      fullImage = createThumbnail(sourceImage); 
      setBgImage(fullImage); 
      is.close(); 
      fcFile.close(); 
     } catch (IOException ex) { 
      handleException(); 
     } catch (OutOfMemoryError oom) { 
      handleOOM(); 
     } 
    } 
    private Image createThumbnail(Image image) { 
     Image thumb = image.scaled(this.getPreferredW(), this.getPreferredH()); 
     return thumb; 
    } 
    ... 
} 

은 내가 수동으로 사진을 열 때, 즉 전화 메모리의 사진 폴더에서 것을 발견, 다음 사진은 변경되지 않습니다!

양식의 배경 이미지로 설정할 때 이미지를 변경하지 않으려면 어떻게해야합니까?

답변

1

기본적으로 LWUIT는 배경 이미지의 배율을 사용합니다. 스타일을 명시 적으로 묻지 않는 한 항상 이미지의 크기를 조정합니다. 타일, 시도 등 정렬 : 이미지가 항상 내가`scaledSmallerRatio 사용하는 경우에도 변경되는

myForm.getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED_CENTER); 
1

파일에서 읽은 이미지 (즉, sourceImage)가 기본 전화 장치와 동일한 지 여부를 확인합니다. 그렇지 않으면 여기에 문제가 있습니다.

sourceImage을 올바르게 볼 수 있다면 크기 조정 된 이미지를 가져 오는 데 몇 가지 사항을 고려해야합니다.

  1. 경우 양식의 contentPane의 너비/높이가 이미지보다 작은

    는 폭/더 나은 옵션보다는 높이를 사용을 것

    Image thumb = image.scaledSmallerRatio(this.getWidth(), this.getHeight()); 참고 : 예, 그 getWidth()하지 getPreferredW (). getPreferredW()로 스케일링을 시도하는 것보다 원하는 결과를 얻지 못한다면.

  2. 이미지의 너비/높이가 contentPane의 너비/높이 양식보다 작은 경우 이미지가 화면에 맞기 때문에 크기를 조정하지 않을 수도 있습니다.

+0

(this.getWidth()를, this.getHeight()); ' – pheromix