-1

i edited my post cause i know that it was impossible to resize the image right after captured it. so i am trying to resize the image after i cropped it.i already implemented some code from here http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#load-bitmap, but it still not resize the image. here is my code :

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;
    }
}

this is the 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;
}

}

pls anyone hand me your help :(

bohr
  • 631
  • 2
  • 9
  • 29
  • two second search in google http://stackoverflow.com/questions/10773511/how-to-resize-an-image-i-picked-from-the-gallery-in-android – Emmanuel Nov 23 '13 at 16:54
  • thanks for your respond @Emmanuel, the problem is a litte different with the link above, because i want to resize after captured and before it save, i don't pick from gallery.. any help ? – bohr Nov 23 '13 at 16:57
  • You need to implement your own camera then. – Emmanuel Nov 23 '13 at 17:20

2 Answers2

1

Is it possible to resize the image right after i capture it before saved to sdCard?

No, because you are not the one taking the picture. Another app is, whichever one is handling your ACTION_IMAGE_CAPTURE request.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • thanks, so how can i resize the image after i croped it ? i already implemented from http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#load-bitmap but it still not work – bohr Nov 23 '13 at 17:47
  • @user2997327: "it still not work" is not a usable description of your problem. Please start a new StackOverflow question, where you post your own code and explain, in detail, what "it still not work" means. – CommonsWare Nov 23 '13 at 17:57
  • 1
    There are many Android developer support sites on the Internet, offering help in many languages. I list several at http://www.andglobe.com. You may have better luck using a site that operates in a language that is more comfortable for you. Otherwise, you will need to explain, in detail, what "it still not resize the image" actually means. For example, does it crash? If so, what did you learn from looking at the stack trace in LogCat? – CommonsWare Nov 23 '13 at 18:30
0

Here's a link for somewhat similar problem and its solution. Check it out!

Community
  • 1
  • 1
Gaurav
  • 5
  • 6
  • Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Mar 04 '14 at 14:30