本文介绍了如何使我的图片光晕效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的GridView的应用程序。现在,我想创建发光效果的我的图片,请帮助我如何创建我的网格视图图像光晕效果?如果有谁知道,请给我一些想法和样品code ....

I created simple gridview application. Now I wish to create glow effect for my images, please help me how to create glow effect for my gird view images? if anyone know please give me some idea and sample code....

这是我的present截图:

This is my present screenshot:

这是我预期的光​​晕效果截图:

And this is my expected glow effect screenshot:

源$ C ​​$ C:

source code:

main.xml中:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
<GridView 
    android:id="@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:columnWidth="90dp"
    android:stretchMode="columnWidth"
    android:gravity="center" />
</LinearLayout>

GridviewExampleActivity.java

GridviewExampleActivity.java

public class GridviewExampleActivity extends Activity
{

public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));
}

public class ImageAdapter extends BaseAdapter{
private Context mContext;

public ImageAdapter(Context c){
mContext = c;
}

public int getCount()
{

    return mThumbIds.length;
 }

public Object getItem(int position)
{ 
    return null;

}

public long getItemId(int position)
{
return 0;
                                }
// create a new ImageView for each item referenced by the Adapter

public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;

if (convertView == null)
{
 imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else
{
imageView = (ImageView) convertView;
                                                }
imageView.setImageResource(R.drawable.icon);

return imageView;
                                }
private Integer[] mThumbIds = {
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon,
        R.drawable.icon, R.drawable.icon};
}   

}

发光效果的屏幕截图:![在此输入图片说明] [3]

glow effect screen shot:![enter image description here][3]

推荐答案

您可以使用下面的code键使每个图像在你的自定义视图的光芒

You can use the following code to make each image in your custom view glow

图像适配器的getView()函数应该是这样的:

the getView() function of the image adapter should be like this:

public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;

if (convertView == null)
{
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8); 
}
else
{
   imageView = (ImageView) convertView;
   Bitmap Image=BitmapFactory.decodeResource(mContext.getResources(),mThumbIds[position]);
        Image=Image.copy(Bitmap.Config.ARGB_8888,true);
        Paint paint=new Paint();
        paint.setDither(true);
        paint.setFilterBitmap(true);
        Bitmap glow=BitmapFactory.decodeResource(mContext.getResources(), R.drawable.glow_image);
        Bitmap bitmap=Bitmap.createBitmap(Image.getWidth(),Image.getHeight(), Config.ARGB_8888);
        Canvas canvas=new Canvas(bitmap);

        canvas.drawBitmap(glow, new Rect(0,0,glow.getWidth(),glow.getHeight()), new Rect(0,0,Image.getWidth(),Image.getHeight()),paint);
        canvas.drawBitmap(Image, new Rect(0,0,Image.getWidth(),Image.getHeight()), new Rect(0+5,0+5,Image.getWidth()-5,Image.getHeight()-5),paint);



        imageView.setImageBitmap(bitmap);


   return imageView;
   }

R.drawable.glow_image是你能为成长效果图像使用PNG图像

R.drawable.glow_image is the png image you can use as the grow effect image

Glow.png

这篇关于如何使我的图片光晕效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:13