개발자/Android

레이아웃에 설정된 이미지 뷰에 동적으로 비트맵 그림 넣기 - Bitmap Image insert in ImageView to Layout file set

지구빵집 2012. 11. 30. 08:30
반응형



레이아웃 파일에서 설정된 이미지 뷰에 비트맵을 이용해서 그린 그림을 그 위치에 넣는 방법을 말합니다.


레이아웃 xml 파일입니다. 빨간자리에 우리가 만들 Bitmap (이미지가 아닙니다. 직접 그린겁니다.)


<TextView

        android:id="@+id/smalltext"

        android:layout_width="wrap_content"

        android:layout_height="42sp"

        android:layout_margin="10sp"

        android:textSize="16sp"

        android:text="작은설명"

        />

        <ImageView

            android:id="@+id/musicimage"

            android:layout_width="300dp"

            android:layout_height="300dp"

            

            />

        <Button

    android:id="@+id/btnnext"  

    android:layout_width="50dp" 

    android:layout_height="wrap_content"

    android:text="다음"

     />


이렇게 해주시고 메인에서는 레이아웃에 설정된 대로 화면을 만들고 아래쪽에 이미지뷰 의 위치에 그린 그림이 동적으로 나오는 거죠.


편의상 함수로 만들었습니다.


private void Create_Image_View() {

// TODO Auto-generated method stub

Bitmap tmpBmp;

         tmpBmp = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);

       

       for(int x = 0; x < 300; x++)

        for(int y = 0; y < 300; y++)

        tmpBmp.setPixel(x, y, Color.DKGRAY);

       

       ImageView tmpIv = (ImageView)findViewById(R.id.musicimage);

       

       tmpIv.setImageBitmap(tmpBmp);

}


musicimage 가 바로 레이아웃에 표기된 이미지 뷰입니다.


이게 또 스크롤이 되면 좋은데... 쩝~ 

반응형