#78 Fixed NPE and incorrect initialisation of tile map when using preview image and initial state.
diff --git a/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java b/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
index 30259ef..3d96dd1 100644
--- a/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
+++ b/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
@@ -880,7 +880,7 @@
         if (tileMap != null && isBaseLayerReady()) {
 
             // Optimum sample size for current scale
-            int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize());
+            int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize(scale));
 
             // First check for missing tiles - if there are any we need the base layer underneath to avoid gaps
             boolean hasMissingTiles = false;
@@ -1075,11 +1075,12 @@
      */
     private synchronized void initialiseBaseLayer(Point maxTileDimensions) {
 
-        fitToBounds(true);
+        satTemp = new ScaleAndTranslate(0f, new PointF(0, 0));
+        fitToBounds(true, satTemp);
 
         // Load double resolution - next level will be split into four tiles and at the center all four are required,
         // so don't bother with tiling until the next level 16 tiles are needed.
-        fullImageSampleSize = calculateInSampleSize();
+        fullImageSampleSize = calculateInSampleSize(satTemp.scale);
         if (fullImageSampleSize > 1) {
             fullImageSampleSize /= 2;
         }
@@ -1091,6 +1092,7 @@
             TileLoadTask task = new TileLoadTask(this, decoder, baseTile);
             task.execute();
         }
+        refreshRequiredTiles(true);
 
     }
 
@@ -1102,7 +1104,7 @@
     private void refreshRequiredTiles(boolean load) {
         if (decoder == null || tileMap == null) { return; }
 
-        int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize());
+        int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize(scale));
 
         // Load tiles of the correct sample size that are on screen. Discard tiles off screen, and those that are higher
         // resolution than required, or lower res than required but not the base layer, so the base layer is always present.
@@ -1159,6 +1161,9 @@
         // If waiting to translate to new center position, set translate now
         if (sPendingCenter != null && pendingScale != null) {
             scale = pendingScale;
+            if (vTranslate == null) {
+                vTranslate = new PointF();
+            }
             vTranslate.x = (getWidth()/2) - (scale * sPendingCenter.x);
             vTranslate.y = (getHeight()/2) - (scale * sPendingCenter.y);
             sPendingCenter = null;
@@ -1174,16 +1179,15 @@
     /**
      * Calculates sample size to fit the source image in given bounds.
      */
-    private int calculateInSampleSize() {
-        float adjustedScale = scale;
+    private int calculateInSampleSize(float scale) {
         if (minimumTileDpi > 0) {
             DisplayMetrics metrics = getResources().getDisplayMetrics();
             float averageDpi = (metrics.xdpi + metrics.ydpi)/2;
-            adjustedScale = (minimumTileDpi/averageDpi) * scale;
+            scale = (minimumTileDpi/averageDpi) * scale;
         }
 
-        int reqWidth = (int)(sWidth() * adjustedScale);
-        int reqHeight = (int)(sHeight() * adjustedScale);
+        int reqWidth = (int)(sWidth() * scale);
+        int reqHeight = (int)(sHeight() * scale);
 
         // Raw height and width of image
         int inSampleSize = 1;