我有一个名为“thepic”的变量,其中包含位图类型的图片。
imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
String realpath=getRealPathFromURI(imageUri);
thepic = BitmapFactory.decodeFile(realpath);**
我有一个名为“thepic”的变量,其中包含位图类型的图片。
imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
String realpath=getRealPathFromURI(imageUri);
thepic = BitmapFactory.decodeFile(realpath);**
您可以通过以下方式实现...您需要下载itextpdf-5.3.2.jar文件并将其附加到您的项目中。
public class WritePdfActivity extends Activity
{
private static String FILE = "mnt/sdcard/FirstPdf.pdf";
static Image image;
static ImageView img;
Bitmap bmp;
static Bitmap bt;
static byte[] bArray;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img=(ImageView)findViewById(R.id.imageView1);
try
{
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
addImage(document);
document.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static void addImage(Document document)
{
try
{
image = Image.getInstance(bArray); ///Here i set byte array..you can do bitmap to byte array and set in image...
}
catch (BadElementException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// image.scaleAbsolute(150f, 150f);
try
{
document.add(image);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
您需要使用第三方库,没有内置的能力。我知道一些反向操作的库(Qoppa、PDFTron、Reade),但它们都很昂贵。听说iText用于编写位图效果不错,但我自己没有使用过。