我如何裁剪位图ImageView的?

编程入门 行业动态 更新时间:2024-10-26 07:35:44
本文介绍了我如何裁剪位图ImageView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这应该是简单,但安卓scaleType =centerCrop不裁剪图像

我得到了图像的 1950年像素的宽,需要通过父母的宽度被裁剪。但安卓scaleType =centerCrop不裁剪图像。我需要什么做的布局,只显示第一个的 400像素的,例如或任何画面/父宽度

抱歉简单的问题 - 试图谷歌它 - 只有复杂的问题存在。而我是新的,所以不要downvote请)

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android/apk/res/android     的xmlns:工具=htt​​p://schemas.android/tool​​s     机器人:ID =@ + ID / RL1     机器人:layout_width =match_parent     机器人:layout_height =match_parent     机器人:背景=@色/ background_color>     < ImageView的             机器人:ID =@ + ID / ver_bottompanelprayer             机器人:layout_width =match_parent             机器人:layout_height =227px             机器人:layout_alignParentBottom =真             机器人:layout_alignParentLeft =真             机器人:scaleType =矩阵             机器人:背景=@可绘制/ ver_bottom_panel_tiled_long/> < / RelativeLayout的>

如果有唯一的办法就是programmaticaly裁剪 - 请给我一个建议与方法

解决方案

好吧,我会糊的评论,因为答案:) - >

RelativeLayout的RL =(RelativeLayout的)findViewById(R.id.rl1); 最后的选项bitmapOptions =新的选项(); bitmapOptions.inDensity =采样大小; bitmapOptions.inTargetDensity = 1; / *`final`改性剂可能是必要的位图* / BMP位= BitmapFactory.de codeResource(getResources(),R.drawable.ver_bottom_panel_tiled_long,bitmapOptions); bmp.setDensity(Bitmap.DENSITY_NONE); BMP = Bitmap.createBitmap(BMP,0,0,rl.getWidth(),bmp.getHeight());

然后在code:

ImageView的IV =(ImageView的)v.findViewById(R.id.ver_bottompanelprayer); 如果(IV!= NULL){   iv.setImageBitmap(BMP); }

干杯:)

I know this should be simple , but android:scaleType="centerCrop" doesn't crop Image

I got image 1950 pixels wide and need it to be cropped by parent's width. But android:scaleType="centerCrop" doesn't crop Image. What do I need to do in layout to show only first 400 pixels, for instance or whatever screen/parent width is

Sorry for simple question - tried to Google it - only complicated questions there. And I'm new, so don't downvote please)

<RelativeLayout xmlns:android="schemas.android/apk/res/android" xmlns:tools="schemas.android/tools" android:id="@+id/rl1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_color"> <ImageView android:id="@+id/ver_bottompanelprayer" android:layout_width="match_parent" android:layout_height="227px" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:scaleType="matrix" android:background="@drawable/ver_bottom_panel_tiled_long" /> </RelativeLayout>

if there's only way is to programmaticaly crop it - please give me an advice with a method

解决方案

Alright, I will paste the comment as answer :) ->

RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl1); final Options bitmapOptions=new Options(); bitmapOptions.inDensity=sampleSize; bitmapOptions.inTargetDensity=1; /*`final` modifier might be necessary for the Bitmap*/ Bitmap bmp= BitmapFactory.decodeResource(getResources(), R.drawable.ver_bottom_panel_tiled_long, bitmapOptions); bmp.setDensity(Bitmap.DENSITY_NONE); bmp = Bitmap.createBitmap(bmp, 0, 0, rl.getWidth(), bmp.getHeight());

Then in the code:

ImageView iv = (ImageView)v.findViewById(R.id.ver_bottompanelprayer); if (iv != null){ iv.setImageBitmap(bmp); }

Cheers :)

更多推荐

我如何裁剪位图ImageView的?

本文发布于:2023-08-02 03:46:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   ImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!