codecamp

鸿蒙OS Image

Image

java.lang.Object

|---ohos.agp.components.Component

|---|---ohos.agp.components.Image

public class Image
extends Component

表示显示图像的组件。

Image继承自Component,用于展示图片资源。

嵌套类摘要

修饰符和类型 描述
static class Image.ScaleMode 表示图像的缩放模式。
从类 ohos.agp.components.Component 继承的嵌套类/接口
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEvent

字段摘要

修饰符和类型 字段 描述
static int CLIP_DIRECTION_NOT_SET 表示未设置的图像剪切方向。
static int CLIP_GRAVITY_NOT_SET 表示未设置的裁剪对齐模式。
static int CLIP_HORIZONTAL 表示水平剪裁模式。
static int CLIP_VERTICAL 表示垂直剪裁模式。
static int GRAVITY_BOTTOM 表示裁剪图像的底部对齐方式。
static int GRAVITY_CENTER 表示裁剪图像的居中对齐方式。
static int GRAVITY_LEFT 表示裁剪图像的左对齐方式。
static int GRAVITY_RIGHT 表示裁剪图像的右对齐方式。
static int GRAVITY_TOP 表示裁剪图像的顶部对齐方式。
从类 ohos.agp.components.Component 继承的字段
ACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLE

构造函数摘要

构造函数 描述
Image(Context context) 默认构造函数用于使用默认属性集和样式创建 Image 实例。
Image(Context context, AttrSet attrSet) 用于在 XML 文件解析后使用指定的属性集和默认样式创建 Image 实例的构造函数。
Image(Context context, AttrSet attrSet, String styleName) 用于在 XML 文件解析后使用指定的属性集和指定的样式创建 Image 实例的构造函数。

方法总结

修饰符和类型 方法 描述
int getClipAlignment() 获取图片裁剪对齐方式。
int getClipDirection() 获取图像裁剪方向。
int getClipGravity() 已弃用。 此更改从 API 版本 5 开始生效。由 getClipAlignment() 替换
float[] getCornerRadii() 获得四个角的半径。
float getCornerRadius() 获取圆角半径。
Element getImageElement() 获取元素的值。
int getMaxHeight() 获取 Image 对象的最大高度。
int getMaxWidth() 获取 Image 对象的最大宽度。
PixelMap getPixelMap() 获取此 Image 上显示的 PixelMap 对象。
PixelMapHolder getPixelMapHolder() 获取此 Image 上显示的 PixelMapHolder 对象。
Image.ScaleMode getScaleMode() 获取图像缩放模式。
void setClipAlignment(int clipAlignment) 设置剪裁对齐模式。
void setClipDirection(int clipDirection) 设置图像剪切方向。
void setClipGravity(int clipGravity) 已弃用。 此更改从 API 版本 5 开始生效。由 setClipAlignment() 替换
void setCornerRadii(float[] radii) 设置此图像的每个圆角的半径。
void setCornerRadius(float radius) 为此图像的四个圆角设置一个统一的半径。
void setImageAndDecodeBounds(int resId) 设置要显示的图片的资源ID,并对图片进行解码。
void setImageElement(Element element) 设置要为此图像显示的元素。
void setMaxHeight(int value) 设置 Image 对象的最大高度。
void setMaxWidth(int value) 设置 Image 对象的最大宽度。
void setPixelMap(int resId) 设置要显示的图像的资源 ID。
void setPixelMap(PixelMap pixelMap) 设置要在组件上显示的图像。
void setPixelMapHolder(PixelMapHolder pixelMapHolder) 设置要为此 Image 显示的 PixelMapHolder 对象。
void setScaleMode(Image.ScaleMode scaleMode) 设置图像的缩放模式。
从类 ohos.agp.components.Component 继承的方法
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, dispatchRestoreState, dispatchSaveState, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findComponentById, findComponentHolderById, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectBoundaryWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, informConfigurationChanged, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onDrag, onRestoreState, onRtlChanged, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectBoundaryWidth, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEvents
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

字段详细信息

CLIP_DIRECTION_NOT_SET

public static final int CLIP_DIRECTION_NOT_SET

表示未设置的图像剪切方向。

CLIP_GRAVITY_NOT_SET

public static final int CLIP_GRAVITY_NOT_SET

表示未设置的裁剪对齐模式。

CLIP_HORIZONTAL

public static final int CLIP_HORIZONTAL

表示水平剪裁模式。

CLIP_VERTICAL

public static final int CLIP_VERTICAL

表示垂直剪裁模式。

GRAVITY_BOTTOM

public static final int GRAVITY_BOTTOM

表示裁剪图像的底部对齐方式。

GRAVITY_CENTER

public static final int GRAVITY_CENTER

表示裁剪图像的居中对齐方式。

GRAVITY_LEFT

public static final int GRAVITY_LEFT

表示裁剪图像的左对齐方式。

GRAVITY_RIGHT

public static final int GRAVITY_RIGHT

表示裁剪图像的右对齐方式。

GRAVITY_TOP

public static final int GRAVITY_TOP

表示裁剪图像的顶部对齐方式。

构造函数详细信息

Image

public Image(Context context)

默认构造函数用于使用默认属性集和样式创建 Image 实例。

参数:

参数名称 参数描述
context 指示应用程序上下文。

Image

public Image(Context context, AttrSet attrSet)

用于在 XML 文件解析后使用指定的属性集和默认样式创建 Image 实例的构造函数。

参数:

参数名称 参数描述
context 指示应用程序上下文。
attrSet 指示要使用的属性集。

Image

public Image(Context context, AttrSet attrSet, String styleName)

用于在 XML 文件解析后使用指定的属性集和指定的样式创建 Image 实例的构造函数。

参数:

参数名称 参数描述
context 指示应用程序上下文。
attrSet 指示要使用的属性集。
styleName 指示要使用的样式名称。

方法详情

setPixelMapHolder

public void setPixelMapHolder(PixelMapHolder pixelMapHolder)

设置要为此 Image 显示的 PixelMapHolder 对象。

此方法在单线程中调用时可以比 setPixelMap(ohos.media.image.PixelMap) 更高效。

参数:

参数名称 参数描述
pixelMapHolder 表示图像对象。

getPixelMapHolder

public PixelMapHolder getPixelMapHolder()

获取此 Image 上显示的 PixelMapHolder 对象。

返回:

返回此 Image 上显示的 PixelMapHolder 对象。

setPixelMap

public void setPixelMap(PixelMap pixelMap)

设置要在组件上显示的图像。

参数:

参数名称 参数描述
pixelMap 表示图像对象。

getPixelMap

public PixelMap getPixelMap()

获取此 Image 上显示的 PixelMap 对象。

返回:

返回此 Image 上显示的 PixelMap 对象。

setImageElement

public void setImageElement(Element element)

设置要为此图像显示的元素。

参数:

参数名称 参数描述
element 指示要设置的元素。

getImageElement

public Element getImageElement()

获取元素的值。

返回:

返回元素的值。

setImageAndDecodeBounds

public void setImageAndDecodeBounds(int resId)

设置要显示的图片的资源ID,并对图片进行解码。

这个界面会根据组件的大小来缩放图片。 使用此接口在不同组件上设置相同的资源 id 可能会导致其中一些显示模糊。 请谨慎使用此界面。

参数:

参数名称 参数描述
resId 指示要显示的图像的资源 ID。

setPixelMap

public void setPixelMap(int resId)

设置要显示的图像的资源 ID。

参数:

参数名称 参数描述
resId 指示要显示的图像的资源 ID。

setClipDirection

public void setClipDirection(int clipDirection)

设置图像剪切方向。

如果图像的大小超过组件的大小,则可以水平或垂直裁剪图像。 水平剪裁不会改变图像的垂直内容。 垂直裁剪不会改变图像的水平内容。

参数:

参数名称 参数描述
clipDirection 指定图像剪切方向。 1表示CLIP_HORIZONTAL,即水平剪裁; 2 表示 CLIP_VERTICAL,即垂直裁剪。

getClipDirection

public int getClipDirection()

获取图像裁剪方向。

返回:

返回图像剪切方向。

setClipGravity

@Deprecated public void setClipGravity(int clipGravity)

已弃用。 此更改从 API 版本 5 开始生效。由 setClipAlignment() 替换

设置剪裁对齐模式。

此方法设置裁剪对齐模式。 例如,如果该值为 GRAVITY_LEFT,则当图像的宽度超过组件的宽度时,将裁剪图像的右侧部分。

参数:

参数名称 参数描述
clipGravity 使用 Image 中的静态辅音指定剪切模式,例如 GRAVITY_LEFT。

getClipGravity

@Deprecated public int getClipGravity()

已弃用。 此更改从 API 版本 5 开始生效。由 getClipAlignment() 替换

获取图片裁剪对齐方式。

返回:

返回图像裁剪对齐模式。

setClipAlignment

public void setClipAlignment(int clipAlignment)

设置剪裁对齐模式。

此方法设置裁剪对齐模式。 例如,如果该值为 GRAVITY_LEFT,则当图像的宽度超过组件的宽度时,将裁剪图像的右侧部分。

参数:

参数名称 参数描述
clipAlignment 使用 Image 中的静态辅音指定剪切模式,例如 GRAVITY_LEFT。

getClipAlignment

public int getClipAlignment()

获取图片裁剪对齐方式。

返回:

返回图像裁剪对齐模式。

setScaleMode

public void setScaleMode(Image.ScaleMode scaleMode)

设置图像的缩放模式。

当图像和组件的大小不同时,此方法对图像进行缩放或裁剪。 有关缩放模式的详细信息,请参见 ScaleMode。

参数:

参数名称 参数描述
scaleMode ScaleMode枚举值,指定缩放模式。

getScaleMode

public Image.ScaleMode getScaleMode()

获取图像缩放模式。

返回:

返回图像缩放模式。

setCornerRadius

public void setCornerRadius(float radius)

为此图像的四个圆角设置一个统一的半径。

参数:

参数名称 参数描述
radius 表示要设置的半径。 该参数的值必须大于0,小于等于0则设置无效。

getCornerRadius

public float getCornerRadius()

获取圆角半径。

返回:

以浮点数返回半径。

setCornerRadii

public void setCornerRadii(float[] radii)

设置此图像的每个圆角的半径。

参数:

参数名称 参数描述
radii 指示要设置的半径数组。

getCornerRadii

public float[] getCornerRadii()

获得四个角的半径。

返回:

以浮点数返回半径。

setMaxHeight

public void setMaxHeight(int value)

设置 Image 对象的最大高度。

仅当 Image 对象的高度设置为 MATCH_CONTENT 时才使用此方法。

参数:

参数名称 参数描述
value 表示 Image 对象的最大高度。

Throws:

Throw名称 Throw描述
IllegalArgumentException 如果指定的高度小于 0,则抛出此异常。

getMaxHeight

public int getMaxHeight()

获取 Image 对象的最大高度。

返回:

返回 Image 对象的最大高度。

setMaxWidth

public void setMaxWidth(int value)

设置 Image 对象的最大宽度。

仅当 Image 对象的宽度设置为 MATCH_CONTENT 时才使用此方法。

参数:

参数名称 参数描述
value 表示 Image 对象的最大宽度。

Throws:

Throw名称 Throw描述
IllegalArgumentException 如果指定的宽度小于 0,则抛出此异常。

getMaxWidth

public int getMaxWidth()

获取 Image 对象的最大宽度。

返回:

返回 Image 对象的最大宽度。

鸿蒙OS FlexLayout.LayoutConfig
鸿蒙OS IndexBar
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

鸿蒙OS 开发

鸿蒙OS 术语

鸿蒙OS Java API参考

鸿蒙OS ohos.aafwk.ability

鸿蒙OS ohos.aafwk.abilityjet.activedata

鸿蒙OS ohos.aafwk.content

鸿蒙OS java.lang

鸿蒙OS java.Util

鸿蒙OS java.Util class

鸿蒙OS ohos.data.dataability

鸿蒙OS ohos.data.dataability class

鸿蒙OS ohos.agp.components

鸿蒙OS ohos.agp.components interface

鸿蒙OS ohos.agp.components class

鸿蒙OS ohos.global.configuration

鸿蒙OS java.io

鸿蒙OS ohos.data.resultset

鸿蒙OS ohos.data.resultset interface

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }