Array Of ImageSurface Overlaps When Displayed In Famo.us
Posted by blogmeister on
June 30, 2014
So I was working with an array of ImageSurface that after doing a shuffle procedure, once displayed, the images of the ImageSurface overlapped incorrectly.
I mean, when I created each ImageSurface at startup and added them to the view, it displayed correctly, overlapping each other sequentially in the correct manner.
However, once that shuffle procedure happened the overlapping got messed up. I did not understand what was happening until I came across a post in the StackOverflow forum that said when you instantiate an ImageSurface, regardless if you had not added it to the context or view, it is automatically added in the rendering tree.
So if you do this:
|
1 2 |
surface2 = new Surface(); surface1 = new Surface(); |
And add these ImageSurface objects to a view like this:
|
1 2 3 |
view = new View(); view.add(surface1); view.add(surface2); |
The surface2 object will always be below surface1. So since my case had to do with shuffling the ImageSurface, the solution was to call the setOptions() method and set its z-index order like this:
|
1 2 |
surface1.setOptions({ properties: { zIndex : 1 } }); surface2.setOptions({ properties: { zIndex : 2 } }); |
In this example, surface2 will then always be on top of surface1.
Share the post "Array Of ImageSurface Overlaps When Displayed In Famo.us"
tags: array, dom, famo.us, imagesurface, overlap, rendering tree, surface, z-index, zindex
No Comments
Reverse Array Content In Java
Posted by blogmeister on
July 22, 2011
|
1 2 3 4 5 |
public static Object[] reverse(Object[] arr) { List<Object> list = Arrays.asList(arr); Collections.reverse(list); return list.toArray(); } |
tags: array, reverse
2 Comments
Convert File To Byte Array Using Java
Posted by blogmeister on
December 10, 2009
This is a nifty helper method to convert a File object into a byte array. I got this method in Java FAQ.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/** * Returns the contents of the file in a byte array * @param file File this method should read * @return byte[] Returns a byte[] array of the contents of the file */ public static byte[] getBytesFromFile(File file) throws IOException { InputStream is = new FileInputStream(file); System.out.println("\nDEBUG: FileInputStream is " + file); // Get the size of the file long length = file.length(); System.out.println("DEBUG: Length of " + file + " is " + length + "\n"); /* * You cannot create an array using a long type. It needs to be an int * type. Before converting to an int type, check to ensure that file is * not loarger than Integer.MAX_VALUE; */ if (length > Integer.MAX_VALUE) { System.out.println("File is too large to process"); return null; } // Create the byte array to hold the data byte[] bytes = new byte[(int)length]; // Read in the bytes int offset = 0; int numRead = 0; while ((offset < bytes.length) && ((numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)) { offset += numRead; } // Ensure all the bytes have been read in if (offset < bytes.length) { throw new IOException("Could not completely read file " + file.getName()); } is.close(); return bytes; } |
Share the post "Convert File To Byte Array Using Java"









