2013-11-23 133 views
-1

我编辑了我的帖子,因为我知道在拍摄它后立即调整图像的大小是不可能的。所以我试图在裁剪它后调整图像大小。我已经在这里实现了一些代码http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#load-bitmap,但它仍然没有调整图像大小。这里是我的代码:调整从Android摄像头拍摄的图像

private void splitImage(File[]listFile, File mediaStorage,int[] chunkNumbers) throws IOException 
{ 
    int rows ,cols; 
    String[] namaFile = new String[listFile.length]; 
    int chunk ; 
    File nf = null; 
    ArrayList<Bitmap> hasilSplit; 
    for(int i=0;i<listFile.length;i++) 
    { 
     int index=1; 
     namaFile[i] = listFile[i].getName(); 
     String nama = namaFile[i].split("\\.")[0]; 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     ResizeGambar rg = new ResizeGambar(); 
     options.inSampleSize = rg.hitungInSampleSize(options); 
     //options.inJustDecodeBounds = false; 

     Bitmap gambarOri = BitmapFactory.decodeFile(listFile[i].getAbsolutePath(),options); 
     Bitmap scaledOri = Bitmap.createScaledBitmap(gambarOri, gambarOri.getWidth(), gambarOri.getHeight(), true); 
     //int chunk = (int)(gambarOri.getWidth() * gambarOri.getHeight()/100); 
     rows =(int) gambarOri.getWidth()/10; 
     cols =(int) gambarOri.getHeight()/10; 
     chunk = rows * cols; 
     chunkNumbers[i] = chunk; 
     System.out.println("Size of ChunkNumbers: " + chunkNumbers[i]); 
     hasilSplit = new ArrayList<Bitmap>(chunk); 
     int count = 0; 
     //koordinat awal chunk 
     for(int x=0;x<rows;x++) 
     { 
      for(int y=0;y<cols;y++) 
      { 
       hasilSplit.add(Bitmap.createBitmap(scaledOri,10*x,10*y,10,10)); 
       nf = new File(mediaStorage.getPath()+File.separator+nama+index+".jpg"); 
       index++; 
       FileOutputStream fo = new FileOutputStream(nf); 
       hasilSplit.get(count).compress(Bitmap.CompressFormat.JPEG, 50, fo); 
       count++; 
       fo.flush(); 
       fo.close(); 
      } 
     } 
     index= 1; 
    } 
} 

这是ResizeGambar.java

package com.example.cobaandroid; 
import android.graphics.BitmapFactory; 
public class ResizeGambar { 

final int reqWidth = 50; 
final int reqHeight=101; 

public ResizeGambar() 
{ 

} 

public int hitungInSampleSize(BitmapFactory.Options options) 
{ 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 1; 
    if(height > reqHeight || width > reqWidth) 
    { 
     final int halfHeight = height/2; 
     final int halfWidth = width/2; 
     while((halfWidth/inSampleSize) > reqWidth && (halfHeight/inSampleSize) > reqHeight) 
     { 
      inSampleSize *=2; 
     } 
    } 
    return inSampleSize; 
} 

}

请人交给我你的帮助:(

+0

在谷歌的二秒搜索http://stackoverflow.com/questions/10773511/how-to-resize-an-image-i-picked-from-the-gallery-in-android – Emmanuel

+0

感谢您的回复@Emmanuel ,问题是与上面的链接有所不同,因为我想在捕获之后调整大小并保存之前,我不从图库中选择..任何帮助? – bohr

+0

然后你需要实现你自己的相机。 – Emmanuel

回答

1

是否有可能调整图像后,我捕获它之前保存到SD卡?

不,因为你不是拍照的人。另一个应用程序是,无论哪个人正在处理您的请求ACTION_IMAGE_CAPTURE

+0

谢谢,那我怎么能调整图像后我蜷缩它?我已经从http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#load-bitmap实现,但它仍然不起作用 – bohr

+0

@ user2997327:“它仍然不工作”不是可用的描述你的问题。请开始一个新的StackOverflow问题,在其中发布自己的代码并详细解释“仍不起作用”的含义。 – CommonsWare

+0

我已经编辑我的帖子@CommonsWare – bohr

0

这里的a link有点类似的问题及其解决方案。一探究竟!

+0

请注意,[只有链接的答案](http://meta.stackoverflow.com/tags/link-only-answers/info)不鼓励,所以答案应该是搜索解决方案的终点(vs.而另一个引用的中途停留时间往往会随着时间推移而过时)。请考虑在此添加独立的摘要,并将链接保留为参考。 – kleopatra

相关问题