我如何编码捕获相机,然后将其转换为相同的相机活动类中的PDF格式?

时间:2011-06-01 06:51:24

标签: android

我将图像存储到SD卡中的代码如下:

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

2 个答案:

答案 0 :(得分:0)

您需要从此处下载iText库 http://www.itextpdf.com/

然后按此将图像转换为PDF Convert image to PDF in Android

答案 1 :(得分:0)

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();