How to find pixel color in custom view?

The ans to your question is that you will get 0 only as in your code you never updated your bitmap with any drawing. All actions were just related to creating the bitmap.

The ans to your question is that you will get 0 only as in your code you never updated your bitmap with any drawing. All actions were just related to creating the bitmap. You have to call apis like myBitmap.

SetPixel(0,0,color). Now if you want to use canvas to write to Bitmap. You have to create a new canvas.

Here is the sudo code: Canvas bmpCanvas = new Canvas(myBitmap); bmpCanvas. DrawText("Android", 50, 280,mAlphaInner); // change pixel values in the bitmap like you are doing above // or you should use bmpCanvas to change the values // and after that canvas. DrawBitmap(myBitmap, 0, 0, null); Here you have the complete implementation, hope code walk through will help you: package com.

Test; import android.content. Context; import android.graphics. Bitmap; import android.graphics.

Canvas; import android.graphics. Paint; import android.util. AttributeSet; import android.view.

View; public class MyAlphabetDraw extends View { Paint mPaint = new Paint(); Paint mAlphaInner = new Paint(); public static Bitmap myBitmap; public static Canvas bmpCanvas; private int intArray; public MyAlphabetDraw(Context context) { super(context); init(); } public MyAlphabetDraw(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } public MyAlphabetDraw(Context context, AttributeSet attrs) { super(context, attrs); init(); } void init() { mPaint. SetDither(true); mPaint. SetColor(0xFFFFFFFF); mPaint.

SetTextSize(100); mPaint. SetStrokeWidth(10); mAlphaInner. SetDither(true); mAlphaInner.

SetColor(0xFF0000FF); mAlphaInner. SetTextSize(98); } @Override protected void onDraw(Canvas canvas) { if (myBitmap == null) { myBitmap = Bitmap. CreateBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.

ARGB_8888); bmpCanvas = new Canvas(myBitmap); intArray = new intmyBitmap.getWidth() * myBitmap.getHeight(); } if (bmpCanvas! = null) { bmpCanvas. DrawCircle(100, 100, 100, mPaint); bmpCanvas.

DrawCircle(100, 100, 90, mAlphaInner); // Code to get copy pixels into int array myBitmap. GetPixels(intArray, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); // Sample code if you put false the image will have white border // if true image will have red color for white pixels if (true) { for (int I = 0; I SetPixels(intArray, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); } } if (myBitmap! = null) canvas.

DrawBitmap(myBitmap, 0, 0, null); } }.

Thanks for replay,after using this code custom view was not displayed. Parent view is emplay..... – Chiru Dec 9 at 10:28 ok then what exactly are you trying to achieve? – havexz Dec 9 at 16:00 I want convert my custom view into pixels and find which pixel has color(white) and replaces with red color.

– Chiru Dec 12 at 5:16 after added canvas. DrawBitmap(myBitmap, 0, 0, null) view was displayed. But It was taken only one pixel(myBitmap.

SetPixel(10,10,Color. WHITE)) ...please help me – Chiru Dec 12 at 8:09 try running your code without the pixel color replacement code and also can you put some screen shots..? – havexz Dec 12 at 8:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions