本文整理汇总了Java中com.lowagie.text.Image类的典型用法代码示例。如果您正苦于以下问题:Java Image类的具体用法?Java Image怎么用?Java Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Image类属于com.lowagie.text包,在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertWriteToPdf
import com.lowagie.text.Image; //导入依赖的package包/类
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
try {
//Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
Image img = Image.getInstance(bufeBufferedImage, null);
Document document = new Document(img);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
//--
document.open();
img.setAbsolutePosition(0, 0);
//--
document.add(img);
//--
document.close();
} catch (DocumentException | IOException e) {
System.out.println("Intern Log : " + e.getMessage());
}
}
示例2: PdfPCell
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>.
* The default padding is 0.25 for a border width of 0.5.
*
* @param image the <CODE>Image</CODE>
* @param fit <CODE>true</CODE> to fit the image to the cell
*/
public PdfPCell(Image image, boolean fit) {
super(0, 0, 0, 0);
borderWidth = 0.5f;
border = BOX;
if (fit) {
this.image = image;
column.setLeading(0, 1);
setPadding(borderWidth / 2);
}
else {
column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0)));
column.setLeading(0, 1);
setPadding(0);
}
}
示例3: createAwtImage
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* Creates a <CODE>java.awt.Image</CODE>. A successful call to the method <CODE>generate()</CODE>
* before calling this method is required.
* @param foreground the color of the bars
* @param background the color of the background
* @return the image
*/
public java.awt.Image createAwtImage(Color foreground, Color background) {
if (image == null)
return null;
int f = foreground.getRGB();
int g = background.getRGB();
Canvas canvas = new Canvas();
int w = width + 2 * ws;
int h = height + 2 * ws;
int pix[] = new int[w * h];
int stride = (w + 7) / 8;
int ptr = 0;
for (int k = 0; k < h; ++k) {
int p = k * stride;
for (int j = 0; j < w; ++j) {
int b = image[p + (j / 8)] & 0xff;
b <<= j % 8;
pix[ptr++] = (b & 0x80) == 0 ? g : f;
}
}
java.awt.Image img = canvas.createImage(new MemoryImageSource(w, h, pix, 0, w));
return img;
}
示例4: generateBarCode
import com.lowagie.text.Image; //导入依赖的package包/类
private Image generateBarCode()
{
try {
Barcode128 code128 = new Barcode128();
code128.setSize(12f);
code128.setBaseline(12f);
code128.setCode(barcode);
Image img = code128.createImageWithBarcode(writer.getDirectContent(), null, null);
img.scalePercent(50, 50);
//img.setAbsolutePosition(PageSize.A4.width() - img.width() - 10,10);
//document.add(img);
return img;
}catch (Exception ex){
ex.printStackTrace();
return null;
}
}
示例5: getPxImage
import com.lowagie.text.Image; //导入依赖的package包/类
/**
*
*/
protected Image getPxImage()
{
if (pxImage == null)
{
try
{
pxImage =
Image.getInstance(
JRLoader.loadBytesFromResource(JRImageLoader.PIXEL_IMAGE_RESOURCE)
);
}
catch(Exception e)
{
throw new JRRuntimeException(e);
}
}
return pxImage;
}
示例6: establecerBarCode
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* M�todo que permite introducir un c�digo de barras code128 que represente el texto
* que se pasa como par�metro. Se debe indicar la p�gina del PDF donde se debe introducir
* el c�digo (normlamente la p�gina 1) y la posici�n absoluta X e Y dentro de la p�gina.
*/
public void establecerBarCode (int Pagina, String texto, int XPos, int YPos) throws Exception
{
Barcode128 code128 = new Barcode128();
code128.setSize(12f);
code128.setBaseline(12f);
code128.setCode(texto);
Image img = code128.createImageWithBarcode(pdfs.getOverContent(Pagina), null, null);
img.setAbsolutePosition(XPos, YPos);
//Se hace un poco mas peque�o en la escala X para que no ocupe tanto
img.scalePercent(75, 100);
pdfs.getOverContent(Pagina).addImage(img);
}
示例7: RtfImage
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* Constructs a RtfImage for an Image.
*
* @param doc The RtfDocument this RtfImage belongs to
* @param image The Image that this RtfImage wraps
* @throws DocumentException If an error occurred accessing the image content
*/
public RtfImage(RtfDocument doc, Image image) throws DocumentException
{
super(doc);
imageType = image.getOriginalType();
if (!(imageType == Image.ORIGINAL_JPEG || imageType == Image.ORIGINAL_BMP
|| imageType == Image.ORIGINAL_PNG || imageType == Image.ORIGINAL_WMF || imageType == Image.ORIGINAL_GIF)) {
throw new DocumentException("Only BMP, PNG, WMF, GIF and JPEG images are supported by the RTF Writer");
}
alignment = image.getAlignment();
width = image.getWidth();
height = image.getHeight();
plainWidth = image.getPlainWidth();
plainHeight = image.getPlainHeight();
this.imageData = getImageData(image);
}
示例8: createAwtImage
import com.lowagie.text.Image; //导入依赖的package包/类
/** Creates a <CODE>java.awt.Image</CODE>.
*
* @param foreground the color of the bars
* @param background the color of the background
*
* @return the image
*/
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background) {
int f = foreground.getRGB();
int g = background.getRGB();
int width = bm.getWidth();
int height = bm.getHeight();
int pix[] = new int[width * height];
byte[][] mt = bm.getArray();
for (int y = 0; y < height; ++y) {
byte[] line = mt[y];
for (int x = 0; x < width; ++x) {
pix[y * width + x] = line[x] == 0 ? f : g;
}
}
java.awt.Canvas canvas = new java.awt.Canvas();
java.awt.Image img = canvas.createImage(new java.awt.image.MemoryImageSource(width, height, pix, 0, width));
return img;
}
示例9: main
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* Adds an Image at an absolute position.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("absolutepositions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
png.setAbsolutePosition(171, 250);
document.add(png);
png.setAbsolutePosition(342, 500);
document.add(png);
// step 5: we close the document
document.close();
}
示例10: main
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* A cell with an image.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ImageCell.pdf"));
// step 3: we open the document
document.open();
Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
float[] widths = { 1f, 4f };
PdfPTable table = new PdfPTable(widths);
table.addCell("This is my dog");
table.addCell(image);
table.addCell("This two");
table.addCell(new PdfPCell(image, true));
table.addCell("This three");
table.addCell(new PdfPCell(image, false));
document.add(table);
// step 5: we close the document
document.close();
}
示例11: printImage
import com.lowagie.text.Image; //导入依赖的package包/类
/** Print a java image */
private void printImage(java.awt.Image image, PdfContentByte cb, float x1, float y1, float x2, float y2, int alignment, int fitMethod, float rotate)
throws BadElementException, IOException, DocumentException {
if(image!=null) {
// Convert to an iText Image
Image img = Image.getInstance(image, null);
printImage(img,cb,x1,y1,x2,y2,alignment,fitMethod,rotate);
}
}
示例12: addImage
import com.lowagie.text.Image; //导入依赖的package包/类
protected void addImage(Image img) throws EmptyStackException {
// if there is an element on the stack...
Object current = stack.pop();
// ...and it's a Chapter or a Section, the Image can be
// added directly
if (current instanceof Chapter
|| current instanceof Section
|| current instanceof Cell) {
((TextElementArray) current).add(img);
stack.push(current);
return;
}
// ...if not, we need to to a lot of stuff
else {
Stack newStack = new Stack();
while (!(current instanceof Chapter
|| current instanceof Section || current instanceof Cell)) {
newStack.push(current);
if (current instanceof Anchor) {
img.setAnnotation(new Annotation(0, 0, 0,
0, ((Anchor) current).getReference()));
}
current = stack.pop();
}
((TextElementArray) current).add(img);
stack.push(current);
while (!newStack.empty()) {
stack.push(newStack.pop());
}
return;
}
}
示例13: createAwtImage
import com.lowagie.text.Image; //导入依赖的package包/类
/** Creates a <CODE>java.awt.Image</CODE>.
* @param foreground the color of the bars
* @param background the color of the background
* @return the image
*/
public java.awt.Image createAwtImage(Color foreground, Color background) {
int f = foreground.getRGB();
int g = background.getRGB();
Canvas canvas = new Canvas();
paintCode();
int h = (int)yHeight;
int pix[] = new int[bitColumns * codeRows * h];
int stride = (bitColumns + 7) / 8;
int ptr = 0;
for (int k = 0; k < codeRows; ++k) {
int p = k * stride;
for (int j = 0; j < bitColumns; ++j) {
int b = outBits[p + (j / 8)] & 0xff;
b <<= j % 8;
pix[ptr++] = (b & 0x80) == 0 ? g : f;
}
for (int j = 1; j < h; ++j) {
System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns);
}
ptr += bitColumns * (h - 1);
}
java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns));
return img;
}
示例14: setThumbnail
import com.lowagie.text.Image; //导入依赖的package包/类
void setThumbnail(Image image, int page) throws PdfException, DocumentException {
PdfIndirectReference thumb = getImageReference(addDirectImageSimple(image));
reader.resetReleasePage();
PdfDictionary dic = reader.getPageN(page);
dic.put(PdfName.THUMB, thumb);
reader.resetReleasePage();
}
示例15: setAlignment
import com.lowagie.text.Image; //导入依赖的package包/类
/**
* ����ͼƬ���뷽ʽ
* @param value ͼƬ���뷽ʽ
*/
public void setAlignment(String value){
if(value.equalsIgnoreCase("center")){
this.image.setAlignment(Image.ALIGN_CENTER);
}
if(value.equalsIgnoreCase("left")){
this.image.setAlignment(Image.ALIGN_LEFT);
}
if(value.equalsIgnoreCase("right")){
this.image.setAlignment(Image.ALIGN_RIGHT);
}
}