我知道如何设置和显示椭圆形状.我知道如何将渐变应用于此形状.我无法弄清楚我是如何得到一个椭圆形渐变来匹配形状.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:startColor="#66FFFFFF"
android:endColor="#00FFFFFF"
android:gradientRadius="100"
android:type="radial" />
</shape>
Run Code Online (Sandbox Code Playgroud)
如果你可以想象,这个渐变在中间有一个半透明的白色发光,然后在边缘渐渐变为alpha零.我需要让它以椭圆形状出现,而不仅仅是圆形渐变.我怎样才能做到这一点?
保存在res/drawable/gradient_box.xml的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
(上面的形状定义取自当时的Android开发者指南.它没有错误.).
让我们尝试将它与TextView一起使用:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Text with some crazy rectangle shape below it."
android:drawableBottom="@drawable/gradient_box"/>
Run Code Online (Sandbox Code Playgroud)
TextView显示就好像drawableBottom属性不在那里!但是,将形状设置为背景可以正常工作:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Text with crazy background"
android:background="@drawable/gradient_box"/>
Run Code Online (Sandbox Code Playgroud)
将实际图像(例如a*.png)设置为android:drawableBottom也可以正常工作.
有任何想法吗?
我想知道是否有任何方法可以将图像/图形转换为Shape?例如,我可以将摩托车形状的轮廓转换为一个,Shape以便我可以在Java中使用它吗?我知道你可以用普通方块或圆角,多边形等来做.但有没有办法做自定义形状?
我可以在可绘制资源中创建文本形状吗?我在谷歌搜索但没有发现任何东西......这是我的可绘制文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="3dp" android:color="#QQffQQ"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item android:right="59dp" android:left="59dp">
<shape android:shape="rectangle">
<solid android:color="£22££20"/>
</shape>
</item>
<item android:top="59dp" android:bottom="59dp">
<shape android:shape="rectangle">
<solid android:color="£20££20"/>
</shape>
</item>
<item>
<!--text should be here-->
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我在Drawable这里试验,发现了一些我无法解释的东西,希望有人可以帮助我.
为什么加入CornerPathEffect到Paint似乎"破"(?)的EVEN_ODD FillType?
更具体地说,我正在按原样测试这个HexagonDrawable类.这就是我得到的:

但是,如果我设置CornerPathEffect为Paint,如下所示(构造函数)...
public HexagonDrawable(int color) {
paint.setColor(color);
paint.setPathEffect(new CornerPathEffect(6)); // added
hexagon.setFillType(Path.FillType.EVEN_ODD);
}
Run Code Online (Sandbox Code Playgroud)
......这就是我得到的:

圆角,是的,但没有轮廓的外观(奇数/偶数/奇数).有人可以解释一下原因吗?
我有以下布局:
<LinearLayout
android:id="@+id/myButton"
android:layout_width="@dimen/logo_radius"
android:layout_height="match_parent"
android:background="@drawable/myShape">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/driver_half"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和以下myShapedrawable:
<selector>
<item><shape android:shape="oval">
<stroke android:color="@android:color/black" android:width="4dp"/>
<solid android:color="@android:color/white" />
</shape></item>
</selector>
Run Code Online (Sandbox Code Playgroud)
我应用了以下过滤器:
myButton.getBackground().setColorFilter( orange, PorterDuff.Mode.ADD );
Run Code Online (Sandbox Code Playgroud)
结果看起来那样:
然后我将myShape改为圆角矩形:
<selector>
<item>
<shape
android:shape="rectangle">
<corners android:bottomLeftRadius="@dimen/logo_radius" android:bottomRightRadius="2dp" android:topLeftRadius="@dimen/logo_radius" android:topRightRadius="2dp"/>
<stroke
android:width="4dp"
android:color="@android:color/black"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
结果看起来像:
左边部分没有应用过滤器,右边部分没有过滤器.
我想得到什么:
如何使用Porter-Duff过滤器正确绘制边框橙色?还有其他选择吗?
例如,如果在列表中的每一行有一个背景,这是一个梯度,会是更好的使用渐变的图像或定义在XML的形状绘制该梯度?这两种方法之间是否存在显着的性能差异?
我有一个在xml中定义的形状:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners
android:bottomLeftRadius="5dp" ##this need change
android:bottomRightRadius="5dp" ##this need change
android:topLeftRadius="5dp" ##this need change
android:topRightRadius="5dp" /> ##this need change
</shape>
Run Code Online (Sandbox Code Playgroud)
我正在创建以下对象:
Drawable shape = getResource().getDrawable(R.drawable.myshape);
我需要修改它的半径(或创建另一个角半径).
如何更改半径?如何以编程方式创建形状?
我想输出一个蓝色的手,但得到不正确的输出.我已经包含输入图片,错误的输出图片和下面的代码.
我认为下面的代码不会填满整个图像,因为图像在右边界尚未关闭.
如何关闭形状并正确填充蓝色?

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
void drawStuff();
void showInputWindow();
void showCannyWindow();
void showContourWindow();
int thresh = 40;
int max_thresh = 120;
Mat img_rgb,img_gray,img_bw,canny_output,drawing;
int main(){
img_rgb = imread("qq.jpg");
blur( img_rgb, img_rgb, Size(3,3) );
cvtColor(img_rgb,img_gray,CV_RGB2GRAY);
showInputWindow();
drawStuff();
cv::waitKey(0);
}
void drawStuff(){
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Canny( img_gray, canny_output, thresh, thresh*2, 3 );
cv::dilate(canny_output, canny_output, cv::Mat(), cv::Point(-1,-1));
showCannyWindow();
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, …Run Code Online (Sandbox Code Playgroud) 我使用nibabellib从nii文件加载数据.我在http://nipy.org/nibabel/gettingstarted.html上阅读了lib的文档,并发现了这一点
无需将任何主图像数据加载到存储器中即可获得该信息.当然,还可以将图像数据作为NumPy阵列访问
这是我的代码加载数据和它的形状
import nibabel as nib
img = nib.load('example.nii')
data = img.get_data()
data = np.squeeze(data)
data = np.copy(data, order="C")
print data.shape
Run Code Online (Sandbox Code Playgroud)
我得到了结果
128, 128, 64
Run Code Online (Sandbox Code Playgroud)
什么是数据形状的顺序?是WidthxHeightxDepth吗?我的意见必须安排为depth, height, width.所以我会用input=data.transpose(2,0,1).这样对吗?谢谢大家
更新:我发现Numpy将按顺序读取图像Height x Width x Depth作为参考http://www.python-course.eu/images/axis.jpeg