2010-12-02 3 views
24

Следующий код - это то, что я получил до сих пор. Однако есть 2 номера:Как сделать эффект свечения вокруг растрового изображения?

  1. Я хочу как внутренние, так и внешние эффекты свечения, которые похожи на параметры смешивания Photoshop. Но мне удалось сделать внешнее свечение, если я установил BlurMaskFilter.Blur.INNER или другое значение, все изображение заблокировано, а не просто краями.

  2. Несмотря на то, что я установил «FF» в качестве значения альфа, цвет свечения все еще очень темный.

    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

Я думаю, что нет никакого способа в андроиде создавать эффекты свечения. вы должны сделать их сами с нуля или найти библиотеку java, которая поддерживает это.

Простейшая вещь, которую я предпочитаю использовать, - это создание слоев изображений. в основном вы определяете относительный макет и помещаете 2 imageViews один поверх другого. просто создайте эффект фотошопа в собственном слое и растрируйте этот слой, сохраните его, чтобы он разместил его поверх вашего изображения. Но будьте осторожны, если вы используете этот метод с большими изображениями, вы можете легко получить превышенное превышение виртуальной машины. Повторная выборка растровых изображений в соответствии с размером представления является довольно хорошим решением для этой проблемы.

Другой способ, который приходит мне на ум, - это рисовать градиенты над вашим изображением (например: радиальный градиент, прозрачный в середине и белом среди краев, чтобы получить белое свечение), но этот путь занимает много времени настройтесь на то, что вам нужно, по моему мнению, не стоит усилий).

Также здесь ссылка на сайт, который делает фильтры изображения 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

Если вы хотите уменьшить радиус свечения вокруг растрового изображения на основании требования U. – Nik 2013-12-23 05:20:42