안드로이드 개발 질문/답변
(글 수 45,052)
hader shader = New BitmapShader (BitmapFactory.decodeResource (getResources () R.drawable.icon) Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
Paint paint = New Paint ();
paint.setShader (shader);
Canvas canvas = getHolder (). lockCanvas ();
canvas.drawPaint (paint);
getHolder (). unlockCanvasAndPost (canvas);
이런식으로 구현하게 되면 0,0 좌표를 중심으로 패턴이 구현됩니다
저는 구상하는 것이 화면의 중앙에 이미지가 그려지고 그 중앙 이미지를 중심으로 패턴이 되게 할려고 구상중입니다
그러면 위나 아래 오른쪽 왼쪽에는 짤려서 이미지가 그려지겠지요

api는 없는 것같고 어떻게 해야 가능할까요 제가 생각하는 것은
다 수학적으로 계산해서 화면 전체 비트맵 위에 각각의 크기를 구하여서 그려주는 것을 생각하고 있는데요
조언 부탁드립니다 꾸벅
2012.03.15 10:04:53
하하 자답입니다 귀찮아서 더 깔끔하게는 안하고 이렇게 했어요..
private void combineImage(Bitmap first, String savePath , int x, int y, int width, int height, int diswidth, int disheight){
Bitmap bitmap = null;
int xwidth = diswidth;
int yheight = disheight;
bitmap = Bitmap.createScaledBitmap(first, xwidth ,yheight , true);
first = Bitmap.createScaledBitmap(first, width ,height , true);
Paint p = new Paint();
p.setDither(true);
p.setFlags(Paint.ANTI_ALIAS_FLAG);
Canvas c = new Canvas(bitmap);
Bitmap temp = null;
int d,e,f = 0;
int dd,ee,ff = 0;
d = x / width;
e = width * d;
f = x - e;
dd = y / height;
ee = height * dd;
ff = y - ee;
for (int b = f-width; b < diswidth ; ) {
c.drawBitmap( first, b , y , p );
b = b + width;
}
if ( y < 0 ) {
for (int b = f-width; b < diswidth ; ) {
c.drawBitmap( first, b , y+height , p );
b = b + width;
}
}
else {
for ( int bb = y-height; bb > -((y / height)+1)*height;) {
for (int b = f-width; b < diswidth ; ) {
c.drawBitmap( first, b , bb , p );
b = b + width;
}
bb -= height;
}
}
if ( (y+height+height) < yheight ){
if ( y < 0 ) {
temp = Bitmap.createBitmap(bitmap, 0, (y+height) ,xwidth , height);
}
else {
temp = Bitmap.createBitmap(bitmap, 0, y ,xwidth , height);
}
for (int b = ff+height; b <= disheight ; ) {
c.drawBitmap( temp, 0 , b , p );
b = b + height;
}
}
else {
if ( (y+height+height) < yheight+height ){
temp = Bitmap.createBitmap(bitmap, 0, y ,xwidth , height);
for (int b = ff+height; b <= disheight ; ) {
c.drawBitmap( temp, 0 , b , p );
b = b + height;
}
}
}
try{
FileOutputStream fos = new FileOutputStream(savePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.close();
if ( temp != null ){
temp.recycle();
temp = null;
}
if ( bitmap != null ){
bitmap.recycle();
bitmap = null;
}
}
catch(Exception e1){e1.printStackTrace();}
}



