This question already has answers here:
How to scale an Image in ImageView to keep the aspect ratio
(26 answers)
Closed 9 years ago.
I can load Images from my assets folder just fine, but now I want to scale the Image (originally 400 x 240, want it to be 800 x 480).
I can't do this with Bitmaps because of 2 reasons: (1), can't seem to create Bitmap from a file without knowing the whole path from C:\ to Assets folder, which is dumb since the whole path is gonna change depending on where app is installed; and (2), can't find a way to convert an Image to a Bitmap. And yes, i've looked up on StackOverflow how to try those/similar things, been looking them up and trying again and again for 3 days all day, no luck.
So how to scale Images? I don't understand why it's so hard to manipulate these things, and what is the difference between Bitmap and Image anyway?
Yes, I'm new to Java/Android as of 3 days ago, but I've done a lotta work in C# and other langs. PS, I know how to create and use Canvas and Paint objects. Ideally, I just need a Image scr_scale_image(Image img, int ScaleX, int Scale y) method.
thanks for any help.
try imagemagick, which provides an api for java (JMagick) - http://www.imagemagick.org/script/index.php
Related
This question already has answers here:
Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image?
(19 answers)
Closed 5 years ago.
Hey guys i just wanna ask When ever we display a background picture in our activity we placed the picture in the drawable folder with sub different folder like
drawable layout_hdpi or layout_mdpi or layout_ldpi or layout_xhdpi
and there is a specific density and dimension for each folder so that it can support multiple devices etc .
i want to ask that do i need to modify my picture for each folder like if my picture dimension is 3000*3000
first i have to modify it to 720*1280 for xhdpi and then put it in layout_xhdpi folder then i modify it for hdpi i.e 400*800 dimension and so on ..
It will take much time to do .Is There is any other easy method
Thanks in Advance !!
You don't need to modify the image for each size. Keeping it to a standard size(eg-1920*1080) would do the work for most of the phones. However for phablets or tablets, you would have to modify the image. Also reduce the images from 3000*3000 to a smaller size as this would increase the app size drastically, would be useless and might cause PNG crunching to fail.
This question already has answers here:
How do I get a Raster from an Image in java?
(2 answers)
Closed 8 years ago.
I have been searching google for stuff like "Java Bitmap", "Create Java Bitmap", etc and cannot seem to find much information. From all of the code examples it looks like all of the bitmap libraries are third party or for android.
What I want to do is very simple. I want to create a small bitmap maybe 10x80, and be able to color each pixel at (x,y). I want to make a small I guess color bar that will show that position of items in a queue by color.
Are there any build in libraries to do this?
There's the java.awt.image.BufferedImage class. This has pixel-specific get/set methods.
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
Here is an example of creating and writing to pixels with BufferedImage:
BufferedImage image = new BufferedImage(10, 80, BufferedImage.TYPE_4BYTE_ABGR);
image.setRGB(5, 20, Color.BLUE.getRGB());
The third parameter on the image is the type, which may vary based on your use, but for basic solid colors the one shown is good. The setRGB uses an int representation of the color so you can't just use a Color constant directly.
You probably don't want to use VolatileImage because the benefits are dubious in current Java implementations. See this stackoverflow question for why it may not help.
Look at the Oracle image turorial for help with this. It explains both your options and how to interact with them.
This question already has answers here:
How to capture an image in android with coordinates
(3 answers)
Closed 9 years ago.
Am new to work on bitmaps in android, and am unable to crop the image between four point ( clearly its not a rectangle in shape).
I convert the image into bitmap and set as background to layout.
now i have four different points(p0,p1,p2,p3)
I have the values of these points .
Now its time to crop the image between these region and show as rectangle shaped bitmap..(ie, as background to another layout.).
Am again mention clearly ,, crop the image between only these points..
ie, inside the region only.
Which way i can solve this problem,? can i use any third-party tool.. the suggest me which those ones.........
Thanks to #all
Here is a solution how to crop image if need a circle.
Based on that code, you can play a bit with Graphics and you will be able to crop your shape.
I will not write code ready for copy paste.
I hope it helps!
Edit:
Maybe Here is your solution!
At first select rectangle region with Bitmap.getPixels
Then avaluate lines which bound your shape.
Change evry pixel in pixels[] which is outsidebounds and set it to 0 (or other value, it will be background of image)
And recreate you image from new dataset.
EDIT: try to use clipping technics http://www.zetcode.com/gfx/java2d/clipping/ or http://www.roseindia.net/java/example/java/swing/graphics2D/clip-area.shtml in example rectangle was used but thos methodics allows any region
This question already has answers here:
Merging two images
(4 answers)
Closed 9 years ago.
So I am basically trying to blend two pictures together by taking the weighted average of each pixel. However, in order for the transformation to apply, the two pictures must be exactly the same size. If not, then the first picture remains unchanged.
http://www.seas.upenn.edu/~cis120/current/hw/hw07/javadoc/Manipulate.html#alphaBlend(double,%20NewPic,%20NewPic)
This is basically what I have to do, but I need clarification. I'm not understanding what I have to do with the colors
Firstly, as this is blatantly homework, you should probably check that you're allowed to get code from the internet. If not you should be careful about what you take from answers you get, less you be accused of plagiarism and/or cheating.
Assuming this is fine however, you will want to interpret each NewPic as a bitmap. Then compare each Pixel in each bitmap with the corresponding Pixel in the second bitmap. Look at the average of each colour and use those to create a pixel in a third bitmap. Once you've created each pixel in the third bitmap, return it.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
MouseListener needs to interact with many object Java
I have a program with many images drawn onto the screen, as well as other things. I have a mouse listener, but what is the most efficient way of detecting what has been clicked on the screen? Because if I have an image 100px x 50px # starting at point 500, 300,
I can't say if (x > 500 && x < 600) etc.. for EVERY image on screen?
Thank you for any help
One way to tackle this kind of problem efficiently is to use a QuadTree, which is a data structure that recursively subdivides the screen. This enables you to only check those images that are in roughly the right part of the screen.
Or a simpler approach would be to simply subdivide the screen into quarters or 16ths, and 'register' each image with the portions of the screen that it covers. This may be less effective if you have any large images, relative to the screen size.
This would probably only be effective if many of your images are static, since the quadtree needs recalculating when image move.
You may find that simply checking every single image is actually fast enough - you didn't say how many images you have, or how long it currently takes to check them all...