📄 image.java
字号:
/**
* Gets the dots-per-inch in the Y direction. Returns 0 if not available.
*
* @return the dots-per-inch in the Y direction
*/
public int getDpiY() {
return dpiY;
}
/**
* Sets the dots per inch value
*
* @param dpiX
* dpi for x coordinates
* @param dpiY
* dpi for y coordinates
*/
public void setDpi(int dpiX, int dpiY) {
this.dpiX = dpiX;
this.dpiY = dpiY;
}
// XY Ratio
/** Holds value of property XYRatio. */
private float XYRatio = 0;
/**
* Gets the X/Y pixel dimensionless aspect ratio.
*
* @return the X/Y pixel dimensionless aspect ratio
*/
public float getXYRatio() {
return this.XYRatio;
}
/**
* Sets the X/Y pixel dimensionless aspect ratio.
*
* @param XYRatio
* the X/Y pixel dimensionless aspect ratio
*/
public void setXYRatio(float XYRatio) {
this.XYRatio = XYRatio;
}
// color, colorspaces and transparency
/** this is the colorspace of a jpeg-image. */
protected int colorspace = -1;
/**
* Gets the colorspace for the image.
* <P>
* Remark: this only makes sense for Images of the type <CODE>Jpeg</CODE>.
*
* @return a colorspace value
*/
public int getColorspace() {
return colorspace;
}
/** Image color inversion */
protected boolean invert = false;
/**
* Getter for the inverted value
*
* @return true if the image is inverted
*/
public boolean isInverted() {
return invert;
}
/**
* Sets inverted true or false
*
* @param invert
* true or false
*/
public void setInverted(boolean invert) {
this.invert = invert;
}
/** ICC Profile attached */
protected ICC_Profile profile = null;
/**
* Tags this image with an ICC profile.
*
* @param profile
* the profile
*/
public void tagICC(ICC_Profile profile) {
this.profile = profile;
}
/**
* Checks is the image has an ICC profile.
*
* @return the ICC profile or <CODE>null</CODE>
*/
public boolean hasICCProfile() {
return (this.profile != null);
}
/**
* Gets the images ICC profile.
*
* @return the ICC profile
*/
public ICC_Profile getICCProfile() {
return profile;
}
/** a dictionary with additional information */
private PdfDictionary additional = null;
/**
* Getter for the dictionary with additional information.
*
* @return a PdfDictionary with additional information.
*/
public PdfDictionary getAdditional() {
return this.additional;
}
/**
* Sets the /Colorspace key.
*
* @param additional
* a PdfDictionary with additional information.
*/
public void setAdditional(PdfDictionary additional) {
this.additional = additional;
}
/**
* Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray.
*/
public void simplifyColorspace() {
if (additional == null)
return;
PdfObject value = additional.get(PdfName.COLORSPACE);
if (value == null || !value.isArray())
return;
PdfObject cs = simplifyColorspace(value);
if (cs.isName())
value = cs;
else {
PdfObject first = (PdfObject)(((PdfArray)value).getArrayList().get(0));
if (PdfName.INDEXED.equals(first)) {
ArrayList array = ((PdfArray)value).getArrayList();
if (array.size() >= 2 && ((PdfObject)array.get(1)).isArray()) {
array.set(1, simplifyColorspace((PdfObject)array.get(1)));
}
}
}
additional.put(PdfName.COLORSPACE, value);
}
/**
* Gets a PDF Name from an array or returns the object that was passed.
*/
private PdfObject simplifyColorspace(PdfObject obj) {
if (obj == null || !obj.isArray())
return obj;
PdfObject first = (PdfObject)(((PdfArray)obj).getArrayList().get(0));
if (PdfName.CALGRAY.equals(first))
return PdfName.DEVICEGRAY;
else if (PdfName.CALRGB.equals(first))
return PdfName.DEVICERGB;
else
return obj;
}
/** Is this image a mask? */
protected boolean mask = false;
/** The image that serves as a mask for this image. */
protected Image imageMask;
/** Holds value of property smask. */
private boolean smask;
/**
* Returns <CODE>true</CODE> if this <CODE>Image</CODE> is a mask.
*
* @return <CODE>true</CODE> if this <CODE>Image</CODE> is a mask
*/
public boolean isMask() {
return mask;
}
/**
* Make this <CODE>Image</CODE> a mask.
*
* @throws DocumentException
* if this <CODE>Image</CODE> can not be a mask
*/
public void makeMask() throws DocumentException {
if (!isMaskCandidate())
throw new DocumentException("This image can not be an image mask.");
mask = true;
}
/**
* Returns <CODE>true</CODE> if this <CODE>Image</CODE> has the
* requisites to be a mask.
*
* @return <CODE>true</CODE> if this <CODE>Image</CODE> can be a mask
*/
public boolean isMaskCandidate() {
if (type == IMGRAW) {
if (bpc > 0xff)
return true;
}
return colorspace == 1;
}
/**
* Gets the explicit masking.
*
* @return the explicit masking
*/
public Image getImageMask() {
return imageMask;
}
/**
* Sets the explicit masking.
*
* @param mask
* the mask to be applied
* @throws DocumentException
* on error
*/
public void setImageMask(Image mask) throws DocumentException {
if (this.mask)
throw new DocumentException(
"An image mask cannot contain another image mask.");
if (!mask.mask)
throw new DocumentException(
"The image mask is not a mask. Did you do makeMask()?");
imageMask = mask;
smask = (mask.bpc > 1 && mask.bpc <= 8);
}
/**
* Getter for property smask.
*
* @return Value of property smask.
*
*/
public boolean isSmask() {
return this.smask;
}
/**
* Setter for property smask.
*
* @param smask
* New value of property smask.
*/
public void setSmask(boolean smask) {
this.smask = smask;
}
/** this is the transparency information of the raw image */
protected int transparency[];
/**
* Returns the transparency.
*
* @return the transparency values
*/
public int[] getTransparency() {
return transparency;
}
/**
* Sets the transparency values
*
* @param transparency
* the transparency values
*/
public void setTransparency(int transparency[]) {
this.transparency = transparency;
}
// deprecated stuff
/**
* Gets the <CODE>String</CODE> -representation of the reference to the
* image.
*
* @return a <CODE>String</CODE>
* @deprecated Use {@link #getUrl()} instead
*/
public URL url() {
return getUrl();
}
/**
* Gets the template to be used as an image.
* <P>
* Remark: this only makes sense for Images of the type <CODE>ImgTemplate
* </CODE>.
*
* @return the template
* @deprecated Use {@link #getTemplateData()} instead
*/
public PdfTemplate templateData() {
return getTemplateData();
}
/**
* Returns an <CODE>Image</CODE> that has been constructed taking in
* account the value of some <VAR>attributes </VAR>.
*
* @param attributes
* Some attributes
* @return an <CODE>Image</CODE>
* @throws BadElementException
* @throws MalformedURLException
* @throws IOException
* @deprecated use ElementFactory.getImage(attributes)
*/
public static Image getInstance(java.util.Properties attributes)
throws BadElementException, MalformedURLException, IOException {
return com.lowagie.text.factories.ElementFactory.getImage(attributes);
}
/**
* Gets the left indentation.
*
* @return the left indentation
* @deprecated Use {@link #getIndentationLeft()} instead
*/
public float indentationLeft() {
return getIndentationLeft();
}
/**
* Gets the right indentation.
*
* @return the right indentation
* @deprecated Use {@link #getIndentationRight()} instead
*/
public float indentationRight() {
return getIndentationRight();
}
/**
* Gets the spacing before this image.
*
* @return the spacing
* @deprecated Use {@link #getSpacingBefore()} instead
*/
public float spacingBefore() {
return getSpacingBefore();
}
/**
* Gets the spacing before this image.
*
* @return the spacing
* @deprecated Use {@link #getSpacingAfter()} instead
*/
public float spacingAfter() {
return getSpacingAfter();
}
/**
* Gets the raw data for the image.
* <P>
* Remark: this only makes sense for Images of the type <CODE>RawImage
* </CODE>.
*
* @return the raw data
* @deprecated Use {@link #getRawData()} instead
*/
public byte[] rawData() {
return getRawData();
}
/**
* Gets the bpc for the image.
* <P>
* Remark: this only makes sense for Images of the type <CODE>RawImage
* </CODE>.
*
* @return a bpc value
* @deprecated Use {@link #getBpc()} instead
*/
public int bpc() {
return getBpc();
}
/**
* Gets the annotation.
*
* @return the annotation that is linked to this image
* @deprecated Use {@link #getAnnotation()} instead
*/
public Annotation annotation() {
return getAnnotation();
}
/**
* Checks if the <CODE>Images</CODE> has to be added at an absolute
* position.
*
* @return a boolean
* @deprecated Use {@link #hasAbsoluteY()} instead
*/
public boolean hasAbsolutePosition() {
return hasAbsoluteY();
}
/**
* Returns the absolute X position.
*
* @return a position
* @deprecated Use {@link #getAbsoluteX()} instead
*/
public float absoluteX() {
return getAbsoluteX();
}
/**
* Returns the absolute Y position.
*
* @return a position
* @deprecated Use {@link #getAbsoluteY()} instead
*/
public float absoluteY() {
return getAbsoluteY();
}
/**
* Gets the plain width of the image.
*
* @return a value
* @deprecated Use {@link #getPlainWidth()} instead
*/
public float plainWidth() {
return getPlainWidth();
}
/**
* Gets the plain height of the image.
*
* @return a value
* @deprecated Use {@link #getPlainHeight()} instead
*/
public float plainHeight() {
return getPlainHeight();
}
/**
* Gets the scaled height of the image.
*
* @return a value
* @deprecated Use {@link #getScaledWidth()} instead
*/
public float scaledWidth() {
return getScaledWidth();
}
/**
* Gets the scaled height of the image.
*
* @return a value
* @deprecated Use {@link #getScaledHeight()} instead
*/
public float scaledHeight() {
return getScaledHeight();
}
/**
* Gets the alignment for the image.
*
* @return a value
* @deprecated Use {@link #getAlignment()} instead
*/
public int alignment() {
return getAlignment();
}
/**
* Gets the alternative text for the image.
*
* @return a <CODE>String</CODE>
* @deprecated Use {@link #getAlt()} instead
*/
public String alt() {
return getAlt();
}
/**
* Gets the colorspace for the image.
* <P>
* Remark: this only makes sense for Images of the type <CODE>Jpeg</CODE>.
*
* @return a colorspace value
* @deprecated Use {@link #getColorspace()} instead
*/
public int colorspace() {
return getColorspace();
}
/**
* Inverts the meaning of the bits of a mask.
*
* @param invert
* <CODE>true</CODE> to invert the meaning of the bits of a
* mask
* @deprecated use setInverted
*/
public void setInvertMask(boolean invert) {
setInverted(invert);
}
/**
* Returns <CODE>true</CODE> if the bits are to be inverted in the mask.
*
* @return <CODE>true</CODE> if the bits are to be inverted in the mask
* @deprecated use isInvert()
*/
public boolean isInvertMask() {
return isInverted();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -