For example: I have a bitmap 20x20, then I do some calculation and I need a new bitmap 30x30 with inside the old one for example in the center of the new bitmap. Is there a way to do that?
I'm creating an image dynamically using a canvas=canvas(mybitmap) but my image has no fixed dimensions. For example, I want to draw a path of a man into space. I create dynamically the image so that, if the man goesto east direction I will have a bitmap that grows in orizontal dimension (1x1 1x2 1x3....) andso on. if he turns to the north direction the bitmap must grow in vertical dimension (1x5 2x5 3x5).
I want not to redraw all the image but copy the old one into the new extended one and add only the new "data".
(I can't draw always on the same image because maybe I have to translate all the image and add some "space" in the first column or the first row of the bitmap")
Why not use a matrix to resize the bitmap?
If you can't just resize the one bitmap, why not still use a matrix then drawBitmap to your canvas(Bitmap) if you really need it done like that...
http://thinkandroid.wordpress.com/2009/12/25/resizing-a-bitmap/
Related
I am fairly new with android development. I am trying to take a 8x8 array of integers and make a 8x8 square (64 squares) using canvas and bitmap, a picture below shows what I want to accomplish. Each square would correspond to the index of the integer array, and the color of the square will change depending on the integers(0-255).
Currently, I am just trying to draw the layout of my application, but I am stuck on drawing the array of squares using canvas and bitmap. I have looked at different sources and the following two seems like very close to what I want to do.
source 1: I declared a 2d bitmap variable like this: Bitmap bmp[][] = new Bitmap[8][8] and tried to use a double for loop, but my app crashes because of
Boolean android.graphics.Bitmap.isRecycled() on a null reference
source 2 I tried alexander zak's answer but I am not sure how to draw squares on to the screen using the Bitmap return value.
Any one have any suggestions on how I can accomplish my goal? thanks for all your help.
Figured it out by:
Create a bitmap objectBitmap bmp = Bitmap.createBitmap(8, 8, bitmap.Config.ARGB_8888)
set each pixels(64) bmp.setPixel(index_of_the_bitmap_x, index_of_the_bitmap_y, int color)using a double for loop or which ever.
Draw a bitmap onto the canvas and scale it to the size of a rectangle: canvas.drawBitmap(bmp, null, destinationRet, null);
I was trying to do really the same functionality of resizing images like in MS Word.
I want to resize BufferedImage but I’m losing some information during process of resizing.
I tried to implement two approaches, but both produced same result.
Before any resizing:
Picture after few resize actions in my application:
First approach:
image = Thumbnails.of(image).size(w,h).asBufferedImage();
Second approach:
image = toBufferedImage(image.getScaledInstance(w, h, Image.SCALE_SMOOTH));
image is instance of BufferedImage, w is new width of image and h is new hight of image
Any idea, what I’m doing wrong?
You're constantly losing information from your image after each resizing attempt. If you want solution (like in MS Word) you have to keep somewhere original image but show only resized copy.
The best solution would be creating an object to store original image and making resized copy on demand. You can improve quality of this solution adding simple cache so you don't actually generate another resized copy of your image for every request but only if your application demands image with different height or width than last time.
I hope I helped you a bit.
I want to have a drawing canvas within my application which will display letter to free draw for practice. Something like the following:
OR
This is the first time I will be implementing this method so a few questions.
Can I have my own background for the canvas? (let's say a chalkboard?)
Do I have to create the letter as image and insert it onto the canvas as Bitmap?
I saw some tutorials but wasn't too clear on how to implement it within app.
I found a solution for you. Having more than 1 Canvas is not the answer (Although may work, I'm still new), but instead draw a seperate Bitmap on top of the first Bitmap (background).
Try this out for size: Overlying Bitmap
You should then be able to edit the overlaying Bitmap without affecting the original Bitmap.
Cheers!
I'd like to create a square thumbnail of an image using Java. I've already managed to resize images through a couple of ways. However I'd like to create a real square image, also from a non-square image.
Example: the source has a size of 200x400 (widht/height)
the target size is 100x100
The algorithm would then need to resize the image to 50x100 and add 25x100 pixels of whitespace each on the left and on the right.
Can anyone help me with this?
Just create a 100x100 background; add the scaled image to it. Use Math.max(width, height) to determine the scale factor. Then, plot the scaled image over the background, use calculations (offset x, offset y) to put it in the proper position.
This is what I need to do. I need to create square thumbnails from a standard photo. The photos are usually portrain layout, so I need to shave off the bottom part of the photo so that the height is equals to the width.
If the image is landscape layout then I need to shave off equal number of pixels from left and right to make it square.
Any ideas how to do this?
My image is BufferedImage object already.
You can use getSubimage to retrieve a cropped version of the original image.