com.lowagie.text.Image类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(739)

本文整理了Java中com.lowagie.text.Image类的一些代码示例,展示了Image类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image类的具体详情如下:
包路径:com.lowagie.text.Image
类名称:Image

Image介绍

[英]An Image is the representation of a graphic element (JPEG, PNG or GIF) that has to be inserted into the document
[中]Image是必须插入文档的图形元素(JPEG、PNG或GIF)的表示形式

代码示例

代码示例来源:origin: javamelody/javamelody

private void writeFileDescriptorCounts(JavaInformations javaInformations)
    throws BadElementException, IOException {
  final long unixOpenFileDescriptorCount = javaInformations.getUnixOpenFileDescriptorCount();
  final long unixMaxFileDescriptorCount = javaInformations.getUnixMaxFileDescriptorCount();
  addCell(getString("nb_fichiers") + ':');
  final Phrase fileDescriptorCountPhrase = new Phrase(
      integerFormat.format(unixOpenFileDescriptorCount) + DIVIDE
          + integerFormat.format(unixMaxFileDescriptorCount) + BAR_SEPARATOR,
      cellFont);
  final Image fileDescriptorCountImage = Image.getInstance(
      Bar.toBarWithAlert(javaInformations.getUnixOpenFileDescriptorPercentage()), null);
  fileDescriptorCountImage.scalePercent(50);
  fileDescriptorCountPhrase.add(new Chunk(fileDescriptorCountImage, 0, 0));
  currentTable.addCell(fileDescriptorCountPhrase);
}

代码示例来源:origin: javamelody/javamelody

private Image getParagraphImage(String resourceFileName) throws DocumentException, IOException {
  Image image = paragraphImagesByResourceName.get(resourceFileName);
  if (image == null) {
    image = getImage(resourceFileName);
    image.scaleAbsolute(16, 16);
    paragraphImagesByResourceName.put(resourceFileName, image);
  }
  return image;
}

代码示例来源:origin: javamelody/javamelody

private void writeRequestGraph(CounterRequest request) throws BadElementException, IOException {
  final JRobin jrobin = collector.getJRobin(request.getId());
  if (jrobin == null) {
    addCell("");
  } else {
    final byte[] img = jrobin.graph(range, 100, 50);
    final Image image = Image.getInstance(img);
    image.scalePercent(50);
    addCell(image);
  }
}

代码示例来源:origin: javamelody/javamelody

private void writeGraph() throws IOException, DocumentException {
  final JRobin jrobin = collector.getJRobin(graphName);
  if (jrobin != null) {
    final byte[] img = jrobin.graph(range, 960, 400);
    final Image image = Image.getInstance(img);
    image.scalePercent(50);
    final PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(0);
    table.addCell("\n");
    table.addCell(image);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    table.addCell(new Phrase(getString("graph_units"), cellFont));
    addToDocument(table);
  } else {
    // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document
    addToDocument(new Phrase("\n", cellFont));
  }
}

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

public static byte[] wrapBMP(Image image) throws IOException {
  if (image.getOriginalType() != Image.ORIGINAL_BMP)
    throw new IOException("Only BMP can be wrapped in WMF.");
  InputStream imgIn;
  byte data[] = null;
  if (image.getOriginalData() == null) {
    imgIn = image.getUrl().openStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int b = 0;
    while ((b = imgIn.read()) != -1)
      out.write(b);
    imgIn.close();
    data = out.toByteArray();
    data = image.getOriginalData();
  int sizeBmpWords = (data.length - 14 + 1) >>> 1;
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  writeWord(os, (int)image.getHeight());
  writeWord(os, (int)image.getWidth());
  writeWord(os, (int)image.getHeight());
  writeWord(os, (int)image.getWidth());
  writeWord(os, 0);
  writeWord(os, 0);
  writeWord(os, (int)image.getHeight());
  writeWord(os, (int)image.getWidth());
  writeWord(os, 0);
  writeWord(os, 0);

代码示例来源:origin: stackoverflow.com

Code128Bean code128 = new Code128Bean();
code128.setHeight(15f);
code128.setModuleWidth(0.3);
code128.setQuietZone(10);
code128.doQuietZone(true);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(baos, "image/x-png", 300, BufferedImage.TYPE_BYTE_BINARY, false, 0);
code128.generateBarcode(canvas, "1234567890");
canvas.finish();

//write to png file
FileOutputStream fos = new FileOutputStream("barcode.png");
fos.write(baos.toByteArray());
fos.flush();
fos.close();

//write to pdf
Image png = Image.getInstance(baos.toByteArray());
png.setAbsolutePosition(400, 685);
png.scalePercent(25);

Document document = new Document(new Rectangle(595, 842));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("barcodes.pdf"));
document.open();
document.add(png);
document.close();

writer.close();

代码示例来源:origin: es.gob.afirma/afirma-crypto-pdf-itext

fillGState[255] = gs;
cb.setGState(gs);
com.lowagie.text.Image image = null;
if(!convertImagesToJPEG){
  image = com.lowagie.text.Image.getInstance(img, bgColor);
  g3.dispose();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
  iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  image = com.lowagie.text.Image.getInstance(baos.toByteArray());
  com.lowagie.text.Image msk = com.lowagie.text.Image.getInstance(mask, null, true);
  msk.makeMask();
  msk.setInverted(true);
  image.setImageMask(msk);
cb.addImage(image, (float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]);
Object url = getRenderingHint(HyperLinkKey.KEY_INSTANCE);
if (url != null && !url.equals(HyperLinkKey.VALUE_HYPERLINKKEY_OFF)) {
  PdfAction action = new  PdfAction(url.toString());
  cb.setAction(action, (float)mx[4], (float)mx[5], (float)(mx[0]+mx[4]), (float)(mx[3]+mx[5]));

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

File myFile1 = new File("/sdcard/ourdata/" + pdfname + ".pdf");
myFile1.createNewFile();
Document pdfDoc = new Document();
PdfWriter docWriter = PdfWriter.getInstance(document,
    new FileOutputStream(myFile1));
document.open();
PdfContentByte cb = docWriter.getDirectContent();
InputStream inputStream = getAssets().open("signature.png");
Bitmap bmp = BitmapFactory.decodeStream(inputStream);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image signature = Image.getInstance(stream.toByteArray());
signature.setAbsolutePosition(400f, 150f);
signature.scalePercent(25f);
document.add(signature);

代码示例来源:origin: stackoverflow.com

Document doc = new Document();
    FileOutputStream fOut = new FileOutputStream(file);
    doc.open();
    ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
    Bitmap bitmap1 = ((BitmapDrawable)img1.getDrawable()).getBitmap();
    bitmap1.compress(Bitmap.CompressFormat.JPEG, 100 , stream1);
    Image myImg1 = Image.getInstance(stream1.toByteArray());
    myImg1.setAlignment(Image.MIDDLE);
    doc.add(myImg1);

代码示例来源:origin: stackoverflow.com

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image signature;
signature = Image.getInstance(stream.toByteArray());
signature.setAbsolutePosition(50f, 100f);
signature.scalePercent(60f);
OutputStream output = new FileOutputStream(myFile);
Document document = new Document();
document.open();
document.add(signature);

代码示例来源:origin: stackoverflow.com

Document doc = new Document();
    FileOutputStream fOut = new FileOutputStream(file);
    doc.open();
     doc.add(p1);
     doc.add(p2);
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.android);
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
     Image myImg = Image.getInstance(stream.toByteArray());
     myImg.setAlignment(Image.MIDDLE);
     Phrase footerText = new Phrase("This is an example of a footer");
     HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
     doc.setFooter(pdfFooter);

代码示例来源:origin: stackoverflow.com

ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.ic_launcher);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
            Image myImg = Image.getInstance(stream.toByteArray());
            myImg.setAlignment(Image.MIDDLE);
            //add image to document
            document.add(myImg);

代码示例来源:origin: stackoverflow.com

//Bitmap bmp passed to method...
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);          
  Image jpg = Image.getInstance(stream.toByteArray());           
  jpg.scalePercent(68);    // or any other number of useful methods.

代码示例来源:origin: stackoverflow.com

try {
     InputStream inputStream = MainActivity.this.getAssets().open(
         "launchscreen.png");
     Bitmap bmp = BitmapFactory.decodeStream(inputStream);
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
     bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
     Image signature;
     signature = Image.getInstance(stream.toByteArray());
     signature.setAbsolutePosition(400f, 150f);
     signature.scalePercent(100f);
     document.add(signature);
         document.close();
   } catch (MalformedURLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }

代码示例来源:origin: stackoverflow.com

try { // Get user Settings GeneralSettings getUserSettings =
  Rectangle rectDoc = document.getPageSize();
  float width = rectDoc.getWidth();
  float height = rectDoc.getHeight();
  float imageStartX = width - document.rightMargin() - 315f;
  float imageStartY = height - document.topMargin() - 80f;
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  byte[] byteArray = stream.toByteArray();
  img.setAlignment(Image.TEXTWRAP);
  img.scaleAbsolute(200f, 50f);
  img.setAbsolutePosition(imageStartX, imageStartY); // Adding Image
  document.add(img);

代码示例来源:origin: stackoverflow.com

File f = new File(filePath);
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image companyLogo = Image.getInstance(stream.toByteArray());

//get size of document
Rectangle documentRect = document.getPageSize();

if(bmp.getWidth()>documentRect.getWidth() || bmp.getHeight()>documentRect.getHeight())
{
  //bitmap is larger than page,so set bitmap's size similar to the whole page 
  companyLogo.scaleAbsolute(documentRect.getWidth(), documentRect.getHeight());
}
else
{
  //bitmap is smaller than page, so add bitmap simply.[note: if you want to fill page by stretching image, you may set size similar to page as above]
  companyLogo.scaleAbsolute(bmp.getWidth(), bmp.getHeight());
}

//set the image with center of the page
companyLogo.setAbsolutePosition((documentRect.getWidth()-image.getScaledWidth())/2, (documentRect.getHeight()-image.getScaledHeight())/2);

代码示例来源:origin: stackoverflow.com

ByteArrayOutputStream baos = new ByteArrayOutputStream();
     Document document = new Document(PageSize.A4, 10, 10, 10, 10);
     PdfWriter.getInstance(document, baos);
     document.open();
     Image image = Image.getInstance(decodedBytes);
     image.scalePercent(50);
     document.add(image);
     document.close();
     DataSource pdfds = new ByteArrayDataSource(baos.toByteArray(), "application/pdf");
     pdfBodyPart.setDataHandler(new DataHandler(pdfds));
     //pngBodyPart.setHeader("Content-ID", "<dashboard>");
     //pngBodyPart.setDisposition(MimeBodyPart.INLINE);
     pdfBodyPart.setFileName("AnnotatedDashboard.pdf");
     multipart.addBodyPart(pdfBodyPart);
     // Send the complete message parts
     message.setContent(multipart);

代码示例来源:origin: stackoverflow.com

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image image = Image.getInstance(stream.toByteArray());
image.scalePercent(70);
image.setAlignment(Image.MIDDLE);
document.add(image);

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-printing

@Override
public void render(PdfContext context) {
  final float w = getSize().getWidth();
  final float h = getSize().getHeight();
  Rectangle iconRect = new Rectangle(0, 0, w, h);
  RenderedImage img;
  try {
    img = legendGraphicService.getLegendGraphic(new RuleMetadata(h, w));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, "PNG", baos);
    context.drawImage(Image.getInstance(baos.toByteArray()), iconRect, null);
  } catch (Exception e) { // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

相关文章

Image类方法