2010-12-02 97 views
24

以下代碼是我到目前爲止得到的。不過,有兩個問題:如何在位圖周圍製作發光效果?

  1. 我想要內外兩種發光效果,看起來與Photoshop的混合選項類似。但我只設法使外部發光,如果我設置BlurMaskFilter.Blur.INNER或其他值,整個圖像被阻止,而不僅僅是邊緣。

  2. 儘管我將「FF」設置爲alpha值,但發光顏色仍然很暗。

    Bitmap alpha = origin.extractAlpha(); 
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(5, BlurMaskFilter.Blur.OUTER); 
    
    Paint paint = new Paint(); 
    paint.setMaskFilter(blurMaskFilter); 
    paint.setColor(0xffffffff); 
    
    Canvas canvas = new Canvas(origin); 
    canvas.drawBitmap(alpha, 0, 0, paint); 
    
    return origin; 
    

alt text

回答

1

我認爲這是在android系統沒有方法來創建發光效果。你必須從頭開始創建它們或者找到一些支持它的java庫。

我最喜歡用的最簡單的東西是製作圖像層。基本上你定義了一個相對的佈局,並把2個imageView放在另一個之上。只需在其自己的圖層中創建photoshop效果並對該圖層進行柵格化,然後將其保存爲png,將其放置在圖像頂部。但要小心如果你使用這種方法的大圖像,你可以很容易地得到該虛擬機超出異常。根據視圖大小對位圖進行重新採樣對於此問題是一個很好的解決方案。

我想到的另一種方法是在圖像上繪製漸變(例如,在中間和邊緣之間透明的徑向漸變,以獲得白色發光),但這種方式需要大量時間調整到你需要什麼,所以在我看來是不值得的努力)。

此外,這裏是一個網站,使Java圖像過濾器的鏈接。也許你可以找到爲你工作的東西。

http://www.jhlabs.com/ip/filters/index.html

-2

如何:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:background="@color/Black" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView android:textColor="@color/White" 
    android:layout_width="wrap_content" 
    android:text="Glowing Text" 
    android:layout_height="wrap_content" 
    android:padding="2dp" 
    android:shadowColor="@color/White" 
    android:shadowDx="0" 
    android:shadowDy="0" 
    android:shadowRadius="3" /> 
</LinearLayout> 

這裏找到:http://blog.stylingandroid.com/archives/378

+3

問題是關於添加輝光位圖,而不是文本! – Rodja 2011-11-30 13:45:07

0
BlurMaskFilter.Blur.NORMAL maybe fit your necessary. 

Comments from official: 
NORMAL(0), //!< blur inside and outside of the original border 
SOLID(1), //!< include the original mask, blur outside 
OUTER(2), //!< just blur outside the original border 
INNER(3); //!< just blur inside the original border 
1

做到這一點的方法是創建一個彩色濾光片輪廓,然後對其進行模糊處理。這個例子可能會有幫助: Android Bitmap contour

4

這裏是解決方案:

http://www.shaikhhamadali.blogspot.ro/2013/06/highlightfocusshadow-image-in-imageview.html

public Bitmap highlightImage(Bitmap src) { 
     // create new bitmap, which will be painted and becomes result image 
     Bitmap bmOut = Bitmap.createBitmap(src.getWidth() + 96, src.getHeight() + 96, Bitmap.Config.ARGB_8888); 
     // setup canvas for painting 
     Canvas canvas = new Canvas(bmOut); 
     // setup default color 
     canvas.drawColor(0, PorterDuff.Mode.CLEAR); 
     // create a blur paint for capturing alpha 
     Paint ptBlur = new Paint(); 
     ptBlur.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); 
     int[] offsetXY = new int[2]; 
     // capture alpha into a bitmap 
     Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY); 
     // create a color paint 
     Paint ptAlphaColor = new Paint(); 
     ptAlphaColor.setColor(0xFFFFFFFF); 
     // paint color for captured alpha region (bitmap) 
     canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor); 
     // free memory 
     bmAlpha.recycle(); 

     // paint the image source 
     canvas.drawBitmap(src, 0, 0, null); 

     // return out final image 
     return bmOut; 
    } 

這將鴿子你的問題更多的圖像位圖效果訪問的博客這些鏈接:

www.shaikhhamadali.blogspot.com

Highlight/focus/shadow the image in ImageView 
Invert the Image in ImageView 
Gray Scale the Image in ImageView (Android) 
set Gamma of image in ImageView 
Saturation Filter Effect on image in ImageView 
Hue Filter Effect on image in ImageView 
Engraving Effect on image in ImageView 
Emboss Effect on image in ImageView 
Smooth Effect on image in ImageView 
Mean Removal Effect on image in ImageView 
Set sharpness of the image in ImageView 
Gaussian Blur the image(Bitmap) in ImageView 
Convolution Matrix for image processing 
Color Boost the image(Bitmap) in ImageView 
Set brightness of the image(increase,decrease) in ImageView 
B/W Contrast and Color Contrast the image in ImageView 
Reducing color depth of image in ImageView 
Sepia-toning Effect (Photography) of image in ImageView 
filter color channels/ set color channels of image in ImageView 
Change/Replacement/Remove pixel colors in ImageView 
Water Mark the Image in ImageView 
5

試試這個。

private void setBackgroundGlow(ImageView imgview, int imageicon,int r,int g,int b) 
{ 
// An added margin to the initial image 
    int margin = 24; 
    int halfMargin = margin/2; 
    // the glow radius 
    int glowRadius = 40; 

    // the glow color 
    int glowColor = Color.rgb(r, g, b); 

    // The original image to use 
    Bitmap src = BitmapFactory.decodeResource(getResources(),imageicon); 

    // extract the alpha from the source image 
    Bitmap alpha = src.extractAlpha(); 

    // The output bitmap (with the icon + glow) 
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin, Bitmap.Config.ARGB_8888); 

    // The canvas to paint on the image 
    Canvas canvas = new Canvas(bmp); 

    Paint paint = new Paint(); 
    paint.setColor(glowColor); 

    // outer glow 
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));//For Inner glow set Blur.INNER 
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint); 

    // original icon 
    canvas.drawBitmap(src, halfMargin, halfMargin, null); 

    imgview.setImageBitmap(bmp); 


} 
+0

如果您想根據要求減少位圖周圍的輝光半徑。 – Nik 2013-12-23 05:20:42