2011-05-11 47 views
3

我有一個應用程序,從相機拍攝一張照片,然後對該照片進行一些圖像處理操作。但是這花了太長時間,所以我想在圖像處理操作之前減小位圖的大小。重要的部分是分辨率必須在較小的圖像中也不錯。在android中是否有庫,或者是否有人知道該操作的算法?如何在不降低Android分辨率的情況下減小位圖的大小?

+0

要縮小整個圖像的大小,或者想要縮小整個圖像的大小並將其保留爲全尺寸? – 2011-05-11 20:28:06

+0

@markransom是的我想減小整個圖像的大小 – barzos 2011-05-11 20:51:14

+0

本質上想要你想要的是某種形式的無損壓縮 - 圖像中的文件格式是什麼?如果它們位於位圖中,那麼將它們保存爲高質量的jpeg可以大大減少文件大小。或者你可以嘗試在它們上面運行一個像'pngcrush'這樣的庫。 – 2011-05-11 22:14:43

回答

1

一種方法是取每個n * n塊的平均值並將其轉換爲單個像素。它不是絕對最銳利的方法,不會完全沒有任何工件,但我認爲你會發現真實世界的結果是可以接受的 - 而且速度非常快。

+0

不會受此操作損壞圖像形狀 – barzos 2011-05-11 20:09:47

+1

@barzos,形狀將保持不變,但細節會減少。 – 2011-05-11 20:26:26

+0

@MarkRansom你能解釋一些代碼嗎? – Ashishsingh 2012-05-31 07:05:09

0
{ Bitmap bit=Shrinkmethod(arrpath1[position], 100, 100); 
     //This reduce the size of image in 1kb size so u can also consider VM nativeheap memory 

        iv.setImageBitmap(bit);//ImageView Obj. 

    } 


    //To reduce the byte size of image in program 

//user defined method to reduce size of image without reducing the quality of img. 
     Bitmap Shrinkmethod(String file,int width,int height){ 
      BitmapFactory.Options bitopt=new BitmapFactory.Options(); 
      bitopt.inJustDecodeBounds=true; 
      Bitmap bit=BitmapFactory.decodeFile(file, bitopt); 

      int h=(int) Math.ceil(bitopt.outHeight/(float)height); 
      int w=(int) Math.ceil(bitopt.outWidth/(float)width); 

      if(h>1 || w>1){ 
       if(h>w){ 
        bitopt.inSampleSize=h; 

       }else{ 
        bitopt.inSampleSize=w; 
       } 
      } 
      bitopt.inJustDecodeBounds=false; 
      bit=BitmapFactory.decodeFile(file, bitopt); 



      return bit; 

     } 

//Try to upload ur project code and idea so that like u and me can get that to develop more android application.. 

Regard, 
pranav 
相關問題