0
我以滑動方式在imageView中顯示圖像,大約需要122〜160 ms,但是當我加密圖像並解密然後顯示它時,大約需要600 - 900 ms取樣加密的圖像需要很多時間Android
什麼讓我困惑的是,時間不解密的時候,它是圖像採樣時間
Ciphered
imgInput = new FileInputStream(imageFile);
startTime = System.currentTimeMillis();
CipherInputStream cs = getCipherStream(imgInput);
endTime = System.currentTimeMillis();
Log.i(TAG,"Ciphered: "+ (endTime - startTime));
startTime = System.currentTimeMillis();
//decode ciphered
bmp = ImagingUtils.decodeSampledBitmapFromResourceMemOpt(cs, 800,
800);
endTime = System.currentTimeMillis();
Log.i(TAG,"Decoding ciphered: "+ (endTime - startTime));
imageView.setImageBitmap(bmp);
unChiphered
imgInput = new FileInputStream(imageFile);
startTime = System.currentTimeMillis();
//decode non-ciphereed
bmp = ImagingUtils.decodeSampledBitmapFromResourceMemOpt(imgInput, 800,
800);
endTime = System.currentTimeMillis();
Log.i(TAG,"decoding unciphered: "+ (endTime - startTime));
imageView.setImageBitmap(bmp);
解碼程序代碼(推薦在另一篇文章在計算器)
byte[] byteArr = new byte[0];
byte[] buffer = new byte[1024];
int len;
int count = 0;
try {
while ((len = inputStream.read(buffer)) > -1) {
if (len != 0) {
if (count + len > byteArr.length) {
byte[] newbuf = new byte[(count + len) * 2];
System.arraycopy(byteArr, 0, newbuf, 0, count);
byteArr = newbuf;
}
System.arraycopy(buffer, 0, byteArr, count, len);
count += len;
}
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(byteArr, 0, count, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
options.inPurgeable = true;
options.inInputShareable = true;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
int[] pids = { android.os.Process.myPid() };
// MemoryInfo myMemInfo = mAM.getProcessMemoryInfo(pids)[0];
// Log.e(TAG, "dalvikPss (decoding) = " + myMemInfo.dalvikPss);
return BitmapFactory.decodeByteArray(byteArr, 0, count, options);
我用解密
public CipherInputStream getCipherStream(InputStream imageis) throws Throwable
{
// Open the input stream
InputStream is = this.getAssets().open("inserva.key");
Cipher c = new EncryptonUtils(is).getCipher(Cipher.DECRYPT_MODE); //cipher.init(mode,secretKey,paramSpec);
CipherInputStream cis = new CipherInputStream(imageis, c);
return cis ;
}
我把你的建議,在改變1024至4096 – MSaudi
我試過這個,但它沒有奏效。 BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); \t \t嘗試{ \t \t \t而((LEN = br.read(緩衝液))> -1){ \t \t \t \t如果(LEN!= 0){ \t \t \t \t \t如果(計數+ LEN > byteArr.length){char _] newbuf = new char [(count + len)* 2]; \t \t \t \t \t \t System.arraycopy(byteArr,0,newbuf,0,count); \t \t \t \t \t \t byteArr = newbuf; \t \t \t \t \t} \t \t \t \t \t System.arraycopy(緩衝液,0,byteArr,計數,LEN); \t \t \t \t \t count + = len; \t \t \t \t} \t \t \t} \t \t \t options.inJustDecodeBounds = TRUE; \t \t \t \t \t \t BitmapFactory.decodeByteArray(new String(byteArr)。getBytes(),0,count,options); – MSaudi
解密時間是相同的,可能會更多,圖像不能正確返回(不顯示) – MSaudi