开发者

splitting an image into mutiple images

I've searched the web for help and although it looked like a solution it turned out to not work so good. For starters I'd like to say I've just jumped into android programming (this is my first day) I really learn by trial and error I'd like it that if you could help me you'd give me hints rather than paste the code in front of me.

my tileset http://img217.imageshack.us/img217/4654/tileseth.png the result http://img199.imageshack.us/img199/7913/resultx.png

the issues I'm having is 1. it is obviousl开发者_开发技巧y not splitting the image in 32 by 32 bits. is what I'm trying to achieve is take my big image and split it into 9* smaller images of 32 by 32 portions. Secondary the image quality gets distorted and I can't work out why. *I don't want to use a 9 patch as there will be more then 9 images soon just a fluke that atm I have 9 images

my code (evidently plagiarized from the internet)

    tilesetSliced = Bitmap.createScaledBitmap(bmp, 96, 96, true);
    tileset[0] = Bitmap.createBitmap(tilesetSliced, 0, 0, 32, 32);
    tileset[1] = Bitmap.createBitmap(tilesetSliced, 32, 0, 32, 32);
    tileset[2] = Bitmap.createBitmap(tilesetSliced, 64, 0, 32, 32);
    tileset[3] = Bitmap.createBitmap(tilesetSliced, 0, 32, 32, 32);
    tileset[4] = Bitmap.createBitmap(tilesetSliced, 32, 32, 32, 32); 
    tileset[5] =  Bitmap.createBitmap(tilesetSliced, 64, 32, 32, 32);    

I'll make it more efficent once I got it working >.< any help would be great

the on draw

public void onDraw(Canvas canvas) {
  //update();
   for(int x=0; x<= mapWidth; x++){
          for(int y = 0; y <= mapHeight; y++){
                   canvas.drawBitmap(tileset[map[x][y]], x *32, y*32, null);
           }
     }
}

o.k some more debugging has shead light on something 1. I removed the scaledbitmap that stopped the quality being destroyed (orginally ahd it due to bugs) however I found out that for some reason it thinks the width of my tileset is 64 when its 96 any help would be nice on this.


You may have more luck with a Bitmap Factory to generate your tilesetSliced. Within it is an Options class that allows you to set the sample size (inSampleSize) which can be used to scale down your image. It may not be precise enough for your needs, however.

Your images are likely distorted due to the scaling down process. Are you able to create these images with the right dimensions or pre-scale them?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜