나는 안드로이드 개발을 처음 사용했습니다. 모든 홈 화면에 배경 무늬를 설정하려면 다음 코드를 사용합니다. 이 코드에서는 먼저 사용자에게 홈 화면 가용성 번호를 입력하도록 요청합니다.모든 홈 화면에 벽 종이 설정
홈 화면이 3 개인 경우 사용자가 sdcard에서 3 장의 배경 화면을 선택하라는 메시지를 표시하고 3 장의 이미지를 가져 와서 장치 기본 화면 크기로 변경하고 해당 비트 맵 이미지를 결합하여 설정합니다. 홈 스크린 벽 종이로.
public void onCreate(Bundle savedInstanceState) {
Display display = getWindowManager().getDefaultDisplay();
dwidth = display.getWidth();
dheight = display.getHeight();
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Log.i("WALLPAPER", "" + dwidth);
Log.i("WALLPAPER", "" + dheight);
width1 = dwidth;
height1 = dheight;
scno = (EditText) findViewById(R.id.screenno);
image = (ImageView) findViewById(R.id.imageview1);
wallpaper=(Button) findViewById(R.id.setwallpaper);
selectimage = (Button) findViewById(R.id.selectimg);
selectimage.setVisibility(View.VISIBLE);
selectimage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(scno.getText().toString().length()<=0){
Toast.makeText(getApplicationContext(),"Enter The number Of Screen",Toast.LENGTH_LONG).show();
}
else{
nmscreen = scno.getText().toString();
noofscreen = Integer.parseInt(nmscreen);
Log.i("WALLPAPERDEMO", "" + noofscreen);
Intent intent1=new Intent();
intent1.setType("image/*");
intent1.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent1, "Complete action using"), PICK_FROM_FILE);
}
}
});
wallpaper.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(scno.getText().toString().length()<=0){
Toast.makeText(getApplicationContext(),"Enter The Number Of Screen",Toast.LENGTH_LONG).show();
}
else{
WallpaperManager mywallpapermanager=WallpaperManager.getInstance(getApplicationContext());
try{
mywallpapermanager.setBitmap(change);
selectimage.setEnabled(true);
}catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
image.setImageBitmap(null);
scno.setText("");
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)return;
Log.d("WALLPAPERDEMO", "Count: " + count);
switch (requestCode) {
case PICK_FROM_FILE:
mImageCaptureUri = data.getData();
Log.i("WALLPAPERDEMO","Calling doCrop() "+mImageCaptureUri.toString());
doCrop();
break;
case CROP_FROM_CAMERA:
Bundle extras = data.getExtras();
if (extras != null) {
photo = extras.getParcelable("data");
Log.d("WALLPAPERDEMO",""+photo.getWidth());
Log.d("WALLPAPERDEMO",""+photo.getWidth());
bitmapArray.add(photo);
count++;
Log.d("WALLPAPERDEMO","Count"+count);
if(count<noofscreen){
Log.d("WALLPAPERDEMO","Outside Switch"+count);
Intent intent1=new Intent();
intent1.setType("image/*");
intent1.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent1, "Complete action using"), PICK_FROM_FILE);
}else{
firstimage = new Bitmap[count];
for (i = 0; i <count; i++) {
firstimage[i] = bitmapArray.get(i);
}
setImage(firstimage);
selectimage.setEnabled(false);
}
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) f.delete();
break;
}
}
}
private void setImage(Bitmap[] firstimage) {
change = Bitmap.createScaledBitmap(firstimage[0], width1, height1, true);
for(int i=1;i<firstimage.length;i++){
Log.d("WALLPAPERDEMO", "" + firstimage[i].getWidth());
Log.d("WALLPAPERDEMO", "change " + change.getWidth());
change1 = Bitmap.createScaledBitmap(firstimage[i], width1, height1, true);
Log.d("WALLPAPERDEMO", "change1 " + change1.getWidth());
change = combineImages(change, change1);
Log.d("WALLPAPERDEMO", ""+change.getWidth());
}
image.setImageBitmap(change);
}
public Bitmap combineImages(Bitmap change1, Bitmap change) {
Bitmap cs = null;
int width, height = 0;
if (change1.getWidth() > change.getWidth()) {
width = change1.getWidth() + change.getWidth();
height = change1.getHeight();
} else {
width = change.getWidth() + change1.getWidth();
height = change.getHeight();
}
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(change, 0f, 0f, null);
comboImage.drawBitmap(change1, change.getWidth(), 0f, null);
return cs;
}
이 응용 프로그램을 실행하고 일부 장치가 제대로 작동하는지 실제 응용 프로그램과 함께 확인합니다. 그러나 일부 장치에서는 화면 크기가 맞지 않습니다. 내 코드의 문제점은 무엇입니까? 장치의 기본 화면 크기를 가져 오는 중이고 선택한 비트 맵 이미지를 기본 화면 크기로 변경 한 후 이미지를 결합하여 이미지 만 결합하고 배경 무늬로 설정합니다.
모든 홈 화면에 배경 무늬를 설정하도록 도와주세요. 미리 감사드립니다.
현재 모바일의 너비와 높이가 표시되고 크기가 배경 무늬로 설정됩니다. 현재 모바일 장치 너비와 높이 나는 다음 code.Display display = getWindowManager(). getDefaultDisplay(); dwidth = display.getWidth(); dheight = display.getHeight(); – Nathiya
현재 모바일의 너비와 높이를 가져오고 해당 크기를 배경 무늬로 설정합니다. 현재 모바일 장치의 너비와 높이가 dwidth 및 dheight 변수에 포함됩니다. 내 코드를 참조하십시오. 또한 setimage 메서드에서 나는 createdcaledbitmap을 사용하여 선택한 이미지 크기를 dwidth 및 deheight로 변경합니다. – Nathiya
당신이 코드 크기 조정을 공유 할 수 있었습니까? 비트 맵 b = BitmapFactory.decodeByteArray (imageAsBytes, 0, imageAsBytes.length) profileImage.setImageBitmap (Bitmap.createScaledBitmap (b, 120, 120, false)); –