my code for storing image into sd card as follow:
public static boolean StoreByteImage(Context mContext, byte[] imageData,int quality, String expName)
{
File sdImageMainDirectory = new File("/sdcard");
FileOutputStream fileOutputStream = null;
String nameFile;
try
{
BitmapFactory.Options options开发者_开发问答=new BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,imageData.length,options);
fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() +"/image/*.jpg");
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
}
you need to download iText library from here http://www.itextpdf.com/
and then follow this to convert image to PDFConvert image to PDF in Android
image from camera
//Bitmap imageBitmap = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
imagebytes = stream.toByteArray();
stream.close();
stream = null;
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILEPATH));
document.open();
Image image = Image.getInstance(imagebytes);
image.scaleAbsolute(imageBitmap.getWidth(),
imageBitmap.getHeight());
image.setAlignment(Image.MIDDLE |Image.ALIGN_MIDDLE);
document.add(image);
document.close();
File file = new File("mnt/sdcard/myPdf.pdf");
byte[] binaryFile = new byte[(int) file.length()];
InputStream fis = new FileInputStream(file);
fis.read(binaryFile);
fis.close();
精彩评论