Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>sample to position icon bitmap over the center of map bitmap: </p> <pre><code>class Scr extends MainScreen { Bitmap mMapBitmap = Bitmap.getBitmapResource("map.png"); Bitmap mIconBitmap = Bitmap.getBitmapResource("icon.png"); Bitmap getOverlappedBitmap(Bitmap map, Bitmap icon) { Graphics g = new Graphics(map); int width = icon.getWidth(); int height = icon.getHeight(); int x = (map.getWidth() - width) / 2; int y = (map.getHeight() - height) / 2; g.drawBitmap(x, y, width, height, icon, 0, 0); return map; } public Scr() { add(new BitmapField(getOverlappedBitmap(mMapBitmap, mIconBitmap))); } } </code></pre> <ul> <li>create array of bitmaps</li> <li>create Graphics from new bitmap and draw all bitmaps with defined alpha value</li> <li>use custom class <a href="http://www.mobiyana.com/code/blackberry/PNGEncoder.java" rel="nofollow noreferrer">PNGEncoder</a> to save bitmap png image</li> </ul> <p>See example</p> <pre><code>class Scr extends MainScreen { Bitmap[] images = new Bitmap[0]; int width = Display.getWidth(); int height = Display.getHeight(); Bitmap bitmap = new Bitmap(width, height); BitmapField bitmapField = new BitmapField(bitmap); public Scr() { add(bitmapField); } MenuItem mAddBitmap = new MenuItem("Add image", 0, 0) { public void run() { Bitmap image = Bitmap.getBitmapResource("img" + (images.length + 1) + ".png"); Arrays.add(images, image); refresh(); } }; MenuItem mClean = new MenuItem("Clean", 0, 0) { public void run() { images = new Bitmap[0]; refresh(); } }; MenuItem mSave = new MenuItem("Save", 0, 0) { public void run() { String mFileName = System.getProperty("fileconn.dir.photos") + "test.bmp"; // bitmap to byte array conversion byte[] bitmapBuffer = new byte[0]; PNGEncoder encoder = new PNGEncoder(bitmap, true); try { bitmapBuffer = encoder.encode(true); } catch (IOException e) { e.printStackTrace(); } writeFile(bitmapBuffer, mFileName); } }; private void writeFile(byte[] data, String fileName) { FileConnection fconn = null; try { fconn = (FileConnection) Connector.open(fileName, Connector.READ_WRITE); } catch (IOException e) { System.out.print("Error opening file"); } if (fconn.exists()) try { fconn.delete(); } catch (IOException e) { System.out.print("Error deleting file"); } try { fconn.create(); } catch (IOException e) { System.out.print("Error creating file"); } OutputStream out = null; try { out = fconn.openOutputStream(); } catch (IOException e) { System.out.print("Error opening output stream"); } try { out.write(data); } catch (IOException e) { System.out.print("Error writing to output stream"); } try { fconn.close(); } catch (IOException e) { System.out.print("Error closing file"); } } void refresh() { bitmap = new Bitmap(width, height); Graphics g = new Graphics(bitmap); for (int i = 0; i &lt; images.length; i++) { g.setGlobalAlpha(100); g.drawBitmap(0, 0, width, height, images[i], 0, 0); } bitmapField.setBitmap(bitmap); } protected void makeMenu(Menu menu, int instance) { super.makeMenu(menu, instance); menu.add(mAddBitmap); menu.add(mSave); menu.add(mClean); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload