我怎么可以转换成位图在Android中的PDF格式位图、转换成、格式、我怎么

2023-09-13 01:18:23 作者:幸福→是有你de味道

**我有位图thepic变量,它是位图型。

  imageUri =(URI)intent.getParcelableExtra(Intent.EXTRA_STREAM);
字符串的真实路径= getRealPathFromURI(imageUri);
thepic = BitmapFactory.de codeFILE(真实路径)**
 

解决方案

您可以用这种方式做......你要下载的 itextpdf-5.3.2.jar 文件,并附上您的项目中。

 公共类WritePdfActivity扩展活动
{
  私有静态字符串文件=MNT / SD卡/ FirstPdf.pdf;

  静态图像的图像;
  静态ImageView的IMG;
  BMP位图;
  静态位图胜;
  静态的byte [] bArray;

  @覆盖
公共无效的onCreate(包savedInstanceState)
{
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    IMG =(ImageView的)findViewById(R.id.imageView1);

    尝试
    {
        文献文件=新的文件();

        PdfWriter.getInstance(文件,新的FileOutputStream(文件));
        document.open();

        addImage(文件);
        document.close();
    }

    赶上(例外五)
    {
        e.printStackTrace();
    }

}
  私有静态无效addImage(文档文件)
  {

    尝试
    {
        图像= Image.getInstance(bArray); ///这里我设置字节array..you能做到位图字节数组,并在图像设置...
    }
    赶上(BadElementException E)
    {
        // TODO自动生成的catch块
        e.printStackTrace();
    }
    赶上(MalformedURLException的E)
    {
        // TODO自动生成的catch块
        e.printStackTrace();
    }
    赶上(IOException异常E)
    {
        // TODO自动生成的catch块
        e.printStackTrace();
    }
     // image.scaleAbsolute(150F,150F);
      尝试
      {
        document.add(图像);
    }赶上(DocumentException E){
        // TODO自动生成的catch块
        e.printStackTrace();
    }
 }
 }
 
如何将jpg转换成pdf的格式

**I have bitmap in "thepic" variable which is of Bitmap type..

imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); 
String realpath=getRealPathFromURI(imageUri); 
thepic = BitmapFactory.decodeFile(realpath);**

解决方案

you can do by this way...you have to download itextpdf-5.3.2.jar file and attach in your project..

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