androidrgb颜色
⑴ android 从一个颜色渐变到另外一个颜色
画图的话
java">LinearGradientlg=newLinearGradient(statrX,statrY,statrX,
stopY,newint[]{Color.rgb(5,254,4),
Color.rgb(189,254,0),Color.rgb(255,142,4),
Color.rgb(248,0,1),Color.rgb(148,0,78),
Color.rgb(121,2,43)},newfloat[]{0,0.2f,0.4f,
0.6f,0.8f,1.0f},TileMode.MIRROR);
//这个是y轴上的变化从绿色到橘黄色到大红色到黑红色。。。
//float数组相当于把Y轴平分为5段
paint.setShader(lg);
线程的话
Handlerhandler=newHandler(){
publicvoidhandleMessage(android.os.Messagemsg){
switch(msg.what){
case100:
textView.setTextColor(colors[msg.arg1]);//颜色的数组,和下面的for的次数要等
break;
default:
break;
}
};
};
privatevoidhuatu(){
//TODOAuto-generatedmethodstub
newThread(newRunnable(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
try{
for(inti=0;i<5;i++){
Thread.sleep(200);
Messagemessage=newMessage();
message.what=100;
message.arg1=i;
handler.sendMessage(message);
}
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}).start();
}
⑵ android 怎样获取图像触摸位置的rgb值
基本介绍
思路:
一
首先需要一张图片,这里由于我的强迫症,我没有写死,而是去图库选择一张照片。
二
获取图片的宽、高,为了精度,这里一定要设置BitmapFactory.Options,通过坐标的形式来获取RGB值,也就是说把一张图片通过坐标分为若干个小点。
上代码:
privateBitmapcomp(Bitmapimage){
ByteArrayOutputStreambaos=newByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG,100,baos);
if(baos.toByteArray().length/1024>1024){
//判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出
baos.reset();//重置baos即清空baos
image.compress(Bitmap.CompressFormat.JPEG,50,baos);
//这里压缩50%,把压缩后的数据存放到baos中
}
ByteArrayInputStreamisBm=newByteArrayInputStream(baos.toByteArray());
BitmapFactory.OptionsnewOpts=newBitmapFactory.Options();
//开始读入图片,此时把options.inJustDecodeBounds设回true了
newOpts.inJustDecodeBounds=true;
Bitmapbitmap=BitmapFactory.decodeStream(isBm,null,newOpts);
newOpts.inJustDecodeBounds=false;
intw=newOpts.outWidth;
inth=newOpts.outHeight;
//现在主流手机比较多是800*500分辨率,所以高和宽我们设置为
floathh=800f;//这里设置高度为800f
floatww=500f;//这里设置宽度为500f
//缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
intbe=1;//be=1表示不缩放
if(w>h&&w>ww){//如果宽度大的话根据宽度固定大小缩放
be=(int)(newOpts.outWidth/ww);
}elseif(w<h&&h>hh){//如果高度高的话根据宽度固定大小缩放
be=(int)(newOpts.outHeight/hh);
}
if(be<=0)
be=1;
newOpts.inSampleSize=be;//设置缩放比例
//重新读入图片,注意此时已经把options.inJustDecodeBounds设回false了
isBm=newByteArrayInputStream(baos.toByteArray());
bitmap=BitmapFactory.decodeStream(isBm,null,newOpts);
returncompressImage(bitmap);//压缩好比例大小后再进行质量压缩
}
重点:一定要设置BitmapFactory.Options newOpts = new BitmapFactory.Options();否则坐标获取不准确
三
通过getPixel(x, y)方法通过坐标拿到我们需要的色值即可,比较简单。
iv_image.setOnTouchListener(newOnTouchListener(){
@Override
publicbooleanonTouch(Viewv,MotionEventevent){
intx=(int)event.getX();
inty=(int)event.getY();
if(event.getAction()==MotionEvent.ACTION_UP){
intcolor=bitmap.getPixel(x,y);
//如果你想做的更细致的话可以把颜色值的RGB拿到做响应的处理
intr=Color.red(color);
intg=Color.green(color);
intb=Color.blue(color);
inta=Color.alpha(color);
Log.i(TAG,"r="+r+",g="+g+",b="+b);
tv_rgb.setText("a="+a+",r="+r+",g="+g+",b="
+b);
btnColor.setTextColor(Color.rgb(r,g,b));
}
returntrue;
}
});
⑶ android 怎么获取rgb文件的颜色值
android可以通过Bitmap.getPixel(x,y)方法获取指定位置的rgb文件的颜色值。分三个步骤:
1、获取点击处的view的bitmap:可以通过ImageView.getBackground()/getDrawable()/getDrawingCache()等方式获取。
2、将点击坐标转换为bitmap内部坐标。
3、getPixel(x,y)即可。
⑷ android位图两个点的Color.red(int)+Color.blue+Color.green相等表示什么意思
Color.red(dst[x0]) + Color.green(dst[x0]) + Color.blue(dst[x0]) == Color.red(dst[x1]) + Color.green(dst[x1]) + Color.blue(dst[x1]) 相等就表示颜色相同呗
450是蓝色 0x00c3ff
可以了解下rgb 颜色
⑸ android字体颜色如何设置
由于你没有自己定义颜色,默认为灰色。
有两种方式设置:
1:在java类中
TextView tv = new TextView(this);
tv.setTextColor(Color.RED);
利用这种方式设置字体颜色。
2:在xml文件中
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="邮箱"
android:textColor=""
/>
在你的TextView中有textColor属性,给属性值为RGB格式就行了.