1

Gud Morning friends. I have create Imageview in row of listview. i also set my bitmap in my Imageview like,

public View getView(final int position, View convertView, ViewGroup parent) {
    View row = convertView;
    UserHolder holder = null;
    Log.d("main", "pos:" + "" + position);

            if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new UserHolder();
        holder.Name = (TextView) row.findViewById(R.id.name);

        holder.Number = (TextView) row.findViewById(R.id.number);

        holder.img=(ImageView) row.findViewById(R.id.image);


        Typeface face=Typeface.createFromAsset(context.getAssets(),"helve.ttf");

        holder.Name.setTypeface(face);
        //holder.Number.setTypeface(face);

        //bit = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);     
       //

        //holder.img.setImageBitmap(getRoundedCornerBitmap(bit, 40));

        row.setTag(holder);
    } else {
        holder = (UserHolder) row.getTag();
    }
    User user = data.get(position); 

    holder.Name.setText(user.getName());
    //holder.img.setImageBitmap(user.getbi());
    holder.img.setImageBitmap(roundCornerImage(user.getbi(),50));
    //holder.img.setImageBitmap(roundCornerImage(BitmapFactory.decodeResource(user.getbi(), R.drawable.ic_launcher),60));
    holder.Number.setText(user.getNumber());




    // Give Different Back Ground To List View---------------------------------------------

    if ((position % 2) == 0) {
        row.setBackgroundResource(R.drawable.list_dark);
    } else {
        row.setBackgroundResource(R.drawable.list_light);
    }




    Log.d("main", "pos:" + "" + position);

    return row;

Now I want to set Bitmap Method in My This imageview. with my code. The methos which i want to add is bellow.

 public Bitmap roundCornerImage(Bitmap src, float round) {
  // Source image size
  int width = src.getWidth();
  int height = src.getHeight();
  // create result bitmap output
  Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
  // set canvas for painting
  Canvas canvas = new Canvas(result);
  canvas.drawARGB(0, 0, 0, 0);

  // configure paint
  final Paint paint = new Paint();
  paint.setAntiAlias(true);
  //paint.setColor);


  // configure rectangle for embedding
  final Rect rect = new Rect(0, 0, width, height);
  final RectF rectF = new RectF(rect);

  // draw Round rectangle to canvas
  canvas.drawRoundRect(rectF, round, round, paint);

  // create Xfer mode
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  // draw source image to canvas
  canvas.drawBitmap(src, rect, rect, paint);

  // return final image
  return result;
 }

How can i add this method in my code. Thank you in Advance.

user3855491
  • 15
  • 1
  • 7
  • do you have source Bitmap? – Pankaj Jul 21 '14 at 04:47
  • ya i have get contact image in bitmap. – user3855491 Jul 21 '14 at 04:48
  • Closed this question as a duplicate as it's exactly a [duplicate question](http://stackoverflow.com/questions/24839366/set-round-corner-method-in-imageview) asked by you for the same issue. Instead of asking a new question, you should edit your existing question and provide enough details which would let you get good answers. – Paresh Mayani Jul 21 '14 at 06:23

2 Answers2

0

Try below code:

holder.img.setImageBitmap(roundCornerImage(user.getbi(),ANY CONSTANT VALUE TO MAKE YOUR IMAGEVIEW ROUND LIKE-1,2));
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

You can usse this method in adaptor--

    public Bitmap getRoundedRectBitmap(Bitmap scalebitmap, int pixels) {
        Bitmap targetBitmap = null;
        try {

            int targetWidth = 150;
            int targetHeight = 150;
            targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(targetBitmap);
            Path path = new Path();
            path.addCircle(
                    ((float) targetWidth) / 2,
                    ((float) targetHeight) / 2,
                    (Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
                    Path.Direction.CW);
            Paint paint = new Paint();
            paint.setColor(Color.GRAY);
            // paint.setStyle(Paint.Style.STROKE);
            paint.setStyle(Paint.Style.FILL);
            paint.setAntiAlias(true);
            paint.setDither(true);
            paint.setFilterBitmap(true);
            canvas.drawOval(new RectF(0, 0, targetWidth, targetHeight), paint);
            // paint.setColor(Color.TRANSPARENT);
            canvas.clipPath(path);
            Bitmap sourceBitmap = scalebitmap;
            canvas.drawBitmap(
                    sourceBitmap,
                    new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap
                            .getHeight()), new RectF(0, 0, targetWidth,
                            targetHeight), paint);

        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (OutOfMemoryError o) {
            o.printStackTrace();
        }
        return targetBitmap;
    }

And you can write method in some constant class and call this method in adaptor like //photo is the Bitmap image which you want to convert in round

Bitmap bitmapImage = Bitmap.createScaledBitmap(photo, 200, 200,true);
    bitmap = imageprocessing.getRoundedRectBitmap(bitmapImage, 100);
Minp
  • 98
  • 1
  • 1
  • 13