예제 #1
0
        private Bitmap GetCachedBitmap(int position)
        {
            string mCachedBitmapFilePath = mPath + position + ".jpg";

            Java.IO.File mCachedBitmapFile = new Java.IO.File(mCachedBitmapFilePath);
            Bitmap       lq = null;

            try {
                if (mCachedBitmapFile.Exists() && mCachedBitmapFile.CanRead())
                {
                    Log.Debug(TAG, "page " + position + " found in cache");
                    lq = BitmapFactory.DecodeFile(mCachedBitmapFilePath);
                    return(lq);
                }
            } catch (Exception ex) {
                //e.printStackTrace();
                // some error with cached file,
                // delete the file and get rid of bitmap
                mCachedBitmapFile.Delete();
                lq = null;

                Log.Error(TAG, ex.Message);
            }
            if (lq == null)
            {
                lq = Bitmap.CreateBitmap(mPreviewSize.X, mPreviewSize.Y, Bitmap.Config.Argb8888);
                mCore.DrawPage(lq, position, mPreviewSize.X, mPreviewSize.Y, 0, 0, mPreviewSize.X, mPreviewSize.Y, new MuPDFCore.Cookie(mCore));

                try
                {
                    lq.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 80, new System.IO.FileStream(mCachedBitmapFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite));
                }
                catch (Java.IO.FileNotFoundException ex)
                {
                    //e.printStackTrace();
                    mCachedBitmapFile.Delete();

                    Log.Error(TAG, ex.Message);
                }
            }
            return(lq);
        }