當前位置:首頁 » 安卓系統 » androidrgb顏色

androidrgb顏色

發布時間: 2023-02-24 22:16:49

⑴ 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格式就行了.

熱點內容
編程找點 發布:2025-05-15 20:43:10 瀏覽:586
php上傳臨時文件夾 發布:2025-05-15 20:43:00 瀏覽:656
impala資料庫 發布:2025-05-15 20:42:12 瀏覽:648
android安裝插件 發布:2025-05-15 20:41:31 瀏覽:241
神秘顧客訪問 發布:2025-05-15 20:33:39 瀏覽:298
安卓市場手機版從哪裡下載 發布:2025-05-15 20:17:28 瀏覽:815
幼兒速演算法 發布:2025-05-15 20:15:08 瀏覽:87
best把槍密碼多少 發布:2025-05-15 20:13:42 瀏覽:549
android安裝程序 發布:2025-05-15 20:13:20 瀏覽:560
c語言跳出死循環 發布:2025-05-15 20:06:04 瀏覽:825