am creating temp Bitmap to draw a Text on it, and the i want to get it Pixels so i can manipulate these pixels (i don’t show this image on screen).
this is the code
Bitmap tempBitmap=Bitmap.createBitmap(200, 400, Bitmap.Config.ARGB_8888);//i've tested all Configs
Canvas tempCanvas=new Canvas(tempBitmap);
tempCanvas.drawColor(Color.WHITE);
tempCanvas.drawText("Hello", 0, 0, mPaint);//mPaint color set to Black
int[] pixels=new int[tempBitmap.getWidth() * tempBitmap.getHeight()];
tempBitmap.getPixels(pixels, 0, tempBitmap.getWidth(), 0, 0, tempBitmap.getWidth(), tempBitmap.getHeight());
but when i print all pixels they all -1 value !! why?
You’re positioning the baseline of the text at (0,0), so you’re drawing it just off the top of the bitmap. Move it down a bit. You can use Paint.getTextBounds to measure the text size, and then use the returned height to move your text downwards.