2010-11-23 7 views
0

私の電話に、1MB以上のサーバに送信したい画像がある場合は、その画像を取り込んで、元の画像を邪魔することなく、より小さなサイズに縮小したいと考えています。私は電話から取得する方法を知っているし、サーバーに送信する方法も知っている、私はちょうどイメージを小さくする方法を知っている必要があります。Androidの画像サイズを大きくする

答えて

1

あなたはそうのようなビットマップを拡大縮小することができます

// Load in your bitmap here, I'll leave this detail up to you 
Bitmap _bitmapPreScale = BitmapFactory.decodeResource(resources, fieldValue); 

int oldWidth = _bitmapPreScale.getWidth(); 
int oldHeight = _bitmapPreScale.getHeight(); 
int newWidth = width; // whatever your desired width and height are 
int newHeight = height; 

// calculate the scale 
float scaleWidth = ((float) newWidth)/oldWidth; 
float scaleHeight = ((float) newHeight)/oldHeight; 

// create a matrix for the manipulation 
Matrix matrix = new Matrix(); 
// resize the bit map 
matrix.postScale(scaleWidth, scaleHeight); 

// recreate the new Bitmap 
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true); 
+0

選択した画像のファイルサイズを確認する方法はありますか?ファイルサイズが> 1MBまたは1024kbの場合は、上に掲載したものと同じように、これらのHD画像だけのファイルサイズの小さい画像には問題ありません。ありがとう – user516883

+0

私はちょうどこのFileファイル=新しいファイル( "infilename")を使うことができると思います。私はそれがトリックを行うだろうと思うfile.lengthを呼び出します – user516883

0

をあなたの元のビットマップから、あなたはしかし、難易度がopen the large image in the first placeにあるかもしれないcreateScaledBitmap(...) を使用することができます。

関連する問題