0

我正在制作一个需要从相机拍摄的图像中扫描的模块。所以基本上,它将jpeg转换为PDF。

我也完成了访问相机并检索位图。我的问题是如何获取 URI 并将其传递给将其转换为 pdf 的类。它不会在android监视器中给出任何错误,所以我不知道我做错了什么。

下面是我的代码:

    public void selectImages() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, CAMERA_REQUEST);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == INTENT_REQUEST_GET_IMAGES && resultCode == Activity.RESULT_OK)
    {
        photo = (Bitmap) data.getExtras().get("data");
        uri = data.getData();

        if(uri.equals(""))
        {
            Toast.makeText(AddUtility.this, "empty", Toast.LENGTH_SHORT).show();
        } else {
            CreatePDF();
        }
    }
}

public void CreatePDF()
{
    Document document = new Document(PageSize.A4, 38, 38, 50, 38);
    try{
        PdfWriter.getInstance(document,new FileOutputStream("Sample.pdf"));
        document.open();
        Image image = Image.getInstance (uri.getPath());
        document.add(new Paragraph("Heading"));
        document.add(image);
        document.close();
    } catch (Exception e)
    {
        e.printStackTrace();
        Toast.makeText(AddUtility.this, e.toString(), Toast.LENGTH_SHORT).show();
    }
}
4

0 回答 0