I am working on an application in which I am using a frame layout. In the frame layout there are three classes as follows:
creating image
checking the pixel of the image the user touches
drawing the image
But when I am touching on the same color, it is giving me a different color value. If anyone wants to see my code then it is there. If you want to check which image is used by me then the images are as follows:
the second image which is used for getting the pixel:
Can any one tell me why it is not giving me correct value of the color on touch on the image
?
Edited1
my edited code of the imagein class is as follow [code after editing4
My guess is that you are making assumptions based on the the pixel coordinates of the image, and not translating the coordinates as they exist once Android resizes your art. You should see what Android thinks the image size is, after it's drawn to your View and make sure that the spot you're touching is the same spot that you're expecting to be touching.
Related
I'm new to android programming and I was wondering about how to get a background image (ImageView) show a drawable with a correct size.
Let me explain well, let's imagine we have this image:
I want this image to get shown with this aspect ratio on all screens.
Since I don't want the image to get stretched, I would like to set manually how my image gets shown, maybe by modifying its scale with thirdy part software.
the problem with this image is that, in portrait mode, it's not guaranteed to see the ball, and so I want to crop the part of my image so that the ball gets shown on the bottom-right edge.
I know that I have to import my drawable for all resolutions, but simply importing does not help... Any suggestions?
EDIT:
I'm facing this problem with dynamic background ImageView, so I'm not going to user xml layout files.
Using scaleType attribute doesn't help for this, or at least not just by setting its value.
I have image view with some lines and curves on it. I need to place the text labels into specific locations on this image. How it can be done?
In details:
Look at the image http://s9.postimg.org/63bq7ax4f/e7c5d09764c43a10537ea1b92a0c0c8b.png
I need "92 PAC" and "95 DRI" to be on that line as well as 2 lines below. Now it shifts upside or downside on different screen sizes.
P.S. If it can simplify the problem, the image can be only in one fixed size in one dpi bucket (despite it's incorrect from the android style).
Thank's
Make a custom view. In your onDraw function, draw that image as a bitmap, then draw the text exactly where you want.
I have this scenario:
An activity with a global layout that has a background image that fills it up.
In such image (provided by designer) there is a white box where some text is supposed to be printed with information from the app at runtime.
We are having problems to understand how we can print in the same position regardless of screen resolution and density... Whenever we change the tablet we get wrong positions for the text...
Any hints?.
Thanks in advance
The best way to do this is to ask the designer to break out the box from the image, and then you aren't worried about the exact nuance of image placement.
Okay, so what if that's not an option? This is where you have to go pixel counting. I would recommend you do the following:
Devote an entire class to getting the text right. This class should extend View, or one of it's subclasses.
In the class, you can determine the size of the image, but not at onCreate. You'll have to determine this in a custom View onMeasure.
This class will have to figure out how to stretch the image appropriately, and based on how it's stretched, figure out where the text box should go.
Hopefully this is enough to get a start on it.
I implemented an application for image zooming based on this tutorial, and it works well.
However, when I zoom in on the image, it loses its clarity. I want to have image zooming that preserves quality and clarity. How can I set that up?
If I understand your question correctly, then awoodland's comment is right, and this is impossible. Despite what TV crime shows use as plot devices, you can't get infinite clarity out of any photograph. If you could, what would stop you from zooming in on any photo repeatedly until you got down to the molecular level?
When you zoom in on a digital image, what you're really doing is ignoring parts of the image and only looking at a small section of it. If you're starting with a zoomed-out image, then zooming in is like unfolding a crumpled-up dot-matrix printout and cutting out a square in the middle to look at; there was more information hidden in the crumpled area that you couldn't see before. But once you "unfold the paper all the way," that's it. If you try to look closer, you can make the individual dots (or pixels) bigger, but you don't get any more useful information because it's not there to begin with.
Converting to a vector image won't help you because of how vector images work. They save the relative positions of important points and then put down whatever size lines and shapes are needed to make a given size work. You can't reverse-engineer the rules from a single static image.
For example, if the top half of a 500px tall photo is solid blue, it could be because a rule says the top 250px of the image should be blue, or it could be because a rule says the top half of the image should be blue. If you're automatically converting to a vector image, the computer has no way to know which of those rules is correct, or if you happen to be looking at a special case of a much more complicated rule. As a result, your generated vector image would expand in completely inappropriate ways.
Main idea is to display 2 square images and then upon button click they should shrink to nothing then display a new image from nothing and grow to normal size. (if possible I'd also like to add a rotation as it shrinks and grows)
I've followed http://developer.android.com/resources/tutorials/opengl/opengl-es20.html
but as I don't have access to an android device till tomorrow I have no way of testing it out right now so I'm hoping anybody might know of existing tutourials which covers anything like this.
I don't want any animation to occur during normal running and it should only occur during my click handler, ofc I still like the images to be displayed till the button clicked just not in motion.
I don't see where the problem is, it is just a simple game of scaling of your object model view.
When you want to scale down ---> you decrease the scaling factor toward zero
Change picture ---> Change binded texture (or change the texture coordinates if you have an atlas)
Scale up ---> increase the scaling factor toward 1.0