树叶云鸿蒙OS教程:鸿蒙OS Image

Image

java.lang.Object

|—ohos.agp.components.Component

|—|—ohos.agp.components.Image

public class Image
extends Component

表示显示图像的组件。

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

嵌套类摘要

修饰符和类型描述
static classImage.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 intCLIP_DIRECTION_NOT_SET表示未设置的图像剪切方向。
static intCLIP_GRAVITY_NOT_SET表示未设置的裁剪对齐模式。
static intCLIP_HORIZONTAL表示水平剪裁模式。
static intCLIP_VERTICAL表示垂直剪裁模式。
static intGRAVITY_BOTTOM表示裁剪图像的底部对齐方式。
static intGRAVITY_CENTER表示裁剪图像的居中对齐方式。
static intGRAVITY_LEFT表示裁剪图像的左对齐方式。
static intGRAVITY_RIGHT表示裁剪图像的右对齐方式。
static intGRAVITY_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 实例的构造函数。

方法总结

修饰符和类型方法描述
intgetClipAlignment()获取图片裁剪对齐方式。
intgetClipDirection()获取图像裁剪方向。
intgetClipGravity()已弃用。 此更改从 API 版本 5 开始生效。由 getClipAlignment() 替换
float[]getCornerRadii()获得四个角的半径。
floatgetCornerRadius()获取圆角半径。
ElementgetImageElement()获取元素的值。
intgetMaxHeight()获取 Image 对象的最大高度。
intgetMaxWidth()获取 Image 对象的最大宽度。
PixelMapgetPixelMap()获取此 Image 上显示的 PixelMap 对象。
PixelMapHoldergetPixelMapHolder()获取此 Image 上显示的 PixelMapHolder 对象。
Image.ScaleModegetScaleMode()获取图像缩放模式。
voidsetClipAlignment(int clipAlignment)设置剪裁对齐模式。
voidsetClipDirection(int clipDirection)设置图像剪切方向。
voidsetClipGravity(int clipGravity)已弃用。 此更改从 API 版本 5 开始生效。由 setClipAlignment() 替换
voidsetCornerRadii(float[] radii)设置此图像的每个圆角的半径。
voidsetCornerRadius(float radius)为此图像的四个圆角设置一个统一的半径。
voidsetImageAndDecodeBounds(int resId)设置要显示的图片的资源ID,并对图片进行解码。
voidsetImageElement(Element element)设置要为此图像显示的元素。
voidsetMaxHeight(int value)设置 Image 对象的最大高度。
voidsetMaxWidth(int value)设置 Image 对象的最大宽度。
voidsetPixelMap(int resId)设置要显示的图像的资源 ID。
voidsetPixelMap(PixelMap pixelMap)设置要在组件上显示的图像。
voidsetPixelMapHolder(PixelMapHolder pixelMapHolder)设置要为此 Image 显示的 PixelMapHolder 对象。
voidsetScaleMode(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。

参数:

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

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 对象的最大宽度。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/163850.html<

(0)
运维的头像运维
上一篇2025-03-19 08:27
下一篇 2025-03-19 08:29

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注