The android.graphics package in Java provides classes for manipulating graphical objects, including Bitmaps. The Bitmap class represents images as bitmaps and allows for the creation, manipulation, and rendering of images in Android applications.
1) Creating a Bitmap object: A new Bitmap object can be created using static method createBitmap(), which takes width, height, and Bitmap.Config as arguments. For example: Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
2) Drawing on a Bitmap: You can draw shapes, texts or images on the Bitmap using a Canvas object. For example: Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); // create a Paint object for drawing paint.setColor(Color.RED); canvas.drawRect(0, 0, 50, 50, paint); // draw a red square in the top-left corner
3) Converting Bitmap to byte array: You can convert a Bitmap object to a byte array using the compress() method. For example: ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); // compress the bitmap to PNG format with 100% quality byte[] byteArray = stream.toByteArray();
The android.graphics package is part of the Android SDK and does not require any external package library.
Java Bitmap - 30 examples found. These are the top rated real world Java examples of android.graphics.Bitmap extracted from open source projects. You can rate examples to help us improve the quality of examples.