public static Bitmap[] load(String src, int width, int height) { Bitmap[] texture = null; InputStream is = null; AssetManager am = resources.getAssets(); String[] nameOfBoxs = null; try { nameOfBoxs = am.list(src); } catch (IOException e) { Log.d("GraphicMaster", "Culd not find folder " + src); } Log.d("GraphicMaster", "NameOfBoxs.length = " + nameOfBoxs.length); texture = new Bitmap[nameOfBoxs.length]; for (int i = 0; i < nameOfBoxs.length; i++) { try { is = resources.getAssets().open(src + "/" + nameOfBoxs[i]); texture[i] = BitmapFactory.decodeStream(is); /* if(width > 0 && height > 0) texture[i] = Bitmap.createScaledBitmap(texture[i], width, height, false);*/ Log.d( "GraphicMaster", "Scaled from " + new Integer((int) (texture[i].getWidth())).toString() + " " + new Integer((int) (texture[i].getHeight())).toString() + " to " + new Integer((int) (texture[i].getWidth() * GameSettings.widthM)).toString() + " " + new Integer((int) (GameSettings.heightM * texture[i].getWidth())).toString()); Log.d( "GraphicMaster", "Scale" + new Double(GameSettings.widthM).toString() + " " + new Double(GameSettings.heightM).toString()); if (GameSettings.widthM != 1 && GameSettings.heightM != 1) texture[i] = Bitmap.createScaledBitmap( texture[i], (int) (texture[i].getWidth() * GameSettings.widthM), (int) (texture[i].getHeight() * GameSettings.heightM), false); } catch (IOException e) { Log.d("GraphicMaster", "Culd not read: " + src + nameOfBoxs[i]); } } return texture; }
/** * Draw the symbol. * * @param ytop The ylocation (in pixels) where the top of the staff starts. */ public void Draw(Canvas canvas, Paint paint, int ytop) { if (!candraw) return; canvas.translate(getWidth() - getMinWidth(), 0); Bitmap numer = images[numerator]; Bitmap denom = images[denominator]; /* Scale the image width to match the height */ int imgheight = SheetMusic.NoteHeight * 2; int imgwidth = numer.getWidth() * imgheight / numer.getHeight(); Rect src = new Rect(0, 0, numer.getWidth(), numer.getHeight()); Rect dest = new Rect(0, ytop, imgwidth, ytop + imgheight); canvas.drawBitmap(numer, src, dest, paint); src = new Rect(0, 0, denom.getWidth(), denom.getHeight()); dest = new Rect( 0, ytop + SheetMusic.NoteHeight * 2, imgwidth, ytop + SheetMusic.NoteHeight * 2 + imgheight); canvas.drawBitmap(denom, src, dest, paint); canvas.translate(-(getWidth() - getMinWidth()), 0); }