Images
[Framework practical 7 of 7]


This practical we're going to finish our application by making it display our data as an image.


Make a copy of last practical's code into a framework7 directory. The first thing we're going to do is add a paint method to our Analyst class.

For the moment we'll just write some text to the frame so we know it works. Using your notes make a paint method in Analyst that writes "Hello World" to the Analyst frame. Test this works and "Hello World" stays even if you minimize and maximize the frame.


Ultimately this is where we want to get our image to, however, we need to deal with a few stages before then. First we need to make a new method in our Storage class that will return an image to us. Add the following method declaration to Storage (make sure Storage also imports java.awt.*; and java.awt.image.*):

   public Image getDataAsImage() {
      // Our Storage code this practical will go here.
   }

Ultimately our algorithm for this method looks like this:

   // Use the methods from this practical to get the data in a 1D double array
   //    re-ranged between 0 and 255 (we'll call it 'data1Dreranged').
   // Make a int array called "pixels" [data1Dreranged.length]

   // loop i = 0 to pixels.length
      // int value = (int) data1Dreranged[i]
      // Use value to make a new greyscale Color
      // pixel[i] = greyscale Color's compressed int
   // end loop
   // Make a MemoryImageSource, remembering that data.length and
   //   data[0].length give you the height and width of the data.
   // Make an Image object.
   // Return the Image object.

Have a go at converting the algorithm above into code, then go on to Part Two, where we'll test it.

NB: Although the Display class we gave you for the assessment does the same job, I wouldn't look at it to see how the above is done, as it uses a slightly different setup with multiple method calls - the above is easier. Do have a look at it after you have got your code working though - you should be able to understand it, even if it is a bit spaghetti.