I am testing a mobile site at the moment on android and have noticed that all my transparent images that have a shadow at the bottom are all rendering extremely poorly. I have tried adding noise>0.5>uniform>monochromatic to the image to solve this but this hasnt helped at all i also tried adding noise>2.0>gausiann>monochromatic but again got no change.
its clear that the image is being rendered as png8 even though im saving out the image as png24. i am also using the most up to date version of the android browser 2.3.3
Can anyone shine any light on this problem?
I know its old but the solution is here.
To summarize: Use following code in onCreate(), between super.onCreate() and setContentView() in your activity:
getWindow().setFormat(PixelFormat.RGBA_8888);
Related
I'm using a TextureView to show a cropped video by setting a scale-matrix with setTransform(matrix) like in this tutorial. So the video gets larger than the view itself.
This works fine for all android versions except for KitKat (4.4).
The problem I have here is that the TextureView's content is not cropped at the view-bounds - it draws the cropped-away part of the video too. However, the outside part is only updated when the layout refreshes (scroll).
A cropped video (nature.mp4) should look like this:
This is what it looks like on KitKat (I'm showing layout bounds in this screenshot):
I tried setting clip-bounds to the view-bounds via setClipBounds(..) - that's not working. Also, I can't use Canvas.clipRect(..) since TextureView's draw-method is final.
It's clearly a bug with KitKat, but has anyone an idea for a workaround?
I am using the standard code stated in the example of the library of https://code.google.com/p/svg-android/wiki/Tutorial, here is my OnCreate method :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
ImageView imageView = (ImageView)findViewById(R.id.imageViewTest);
// Set the background color to white
imageView.setBackgroundColor(Color.GRAY);
// Parse the SVG file from the resource
SVG svg = SVGParser.getSVGFromResource(getResources(), R.drawable.android);
//Get a drawable from the parsed SVG and set it as the drawable for the ImageView
imageView.setImageDrawable(svg.createPictureDrawable());
}
I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
It does not give any error but it also does not display the image.
I was earlier getting doubts that the image is incorrect, then I used the one in the same example.
Yet it is not displaying the image nor giving any error.
Please suggest how to debug further.
On newer devices have hardware rendering turned on by default so you need to explicitly turn on software rendering.
use this after your code:
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
Your problem is almost certainly hardware acceleration. You may need to set the View LayerType to software mode.
See Having issue on Real Device using vector image in android. SVG-android
If that doesn't fix it, then it may be an issue with svg-android, which can have trouble rendering correctly anything other than simple SVGs. You might have better luck with my library AndroidSVG.
The best practice for SVG on Android is going to be to use a tool to convert your SVG to PNG at the size(s) you're interested in. Existing SVG support for Android is not comprehensive of what you're likely to find in an SVG file, and even if it were, the support is not built into the OS so using them directly is out of source .
If the library you're working with can process the SVGs you have well, you can make it work for every icon but not through the standard Android API; you'll need to create a custom view. Around months ago I used the library you linked and at that time it had trouble with many SVGs I had created in Inkscape or downloaded from various places. Perhaps its support has improved since then, but I recommend testing it with the exact SVGs you plan to use before you write a lot of custom code for it.
I'm writing an app that requires displaying a semi-transparent PNG layer over a camera preview. Everything was fine until I wanted to publish it and make sure it works also on Android 2.x. It seems that on older versions of Android, the camera preview causes the drawable (in my case, a subclass of ImageView) to not show. When I get rid of the preview, it works just fine - the drawable is visible as it should. It works like this both on the emulator and on real devices.
Here how it looks like on Android 2.3:
and 4.2.2:
I think there would be too much code to paste here, so I've isolated the problematic parts into a small project: http://krzeminski.it/wp-content/uploads/2013/09/DrawableTest.zip. The most interesting and probably guilty class is CameraPreview.
Also, I'm not sure why the preview itself doesn't work. I've read that on Android 2.x emulators, the test image from the emulated camera is just this plain white, so I assumed it's ok. However, my friend tested the app on his phone with Android 2.3 and the preview appeared to be plain black. I guess it's a subject for a separate question, but maybe you'll notice something in the code.
I've spent probably 2 days now to solve these two problems, so any clues would be really helpful. Thank you!
I ran into this issue a while back. I remember that a post on SO recommended that you shouldn't use ImageView#getImageMatrix(). Reasoning given was:
public Matrix getImageMatrix ():
Return the view's optional matrix. This is applied to the view's
drawable when it is drawn. If there is not matrix, this method will
return an identity matrix. Do not change this matrix in place but make
a copy. If you want a different matrix applied to the drawable, be
sure to call setImageMatrix().
Even after reading through this, I couldn't/don't understand what difference this makes. I sorted the problem out by using:
Matrix matrix = new Matrix();
May be you're dealing with the same issue. Give this a try.
I don't have Android 2.3 device. But I think probably you can try two ways:
1. change FrameLayout to RelativeLayout
2. programmatically add views:
mLayout.addView(mPreview);
mLayout.addView(mImageView);
mLayout.addView(mTextView);
I have an image that is circular and I want to make the other junk in the image to be transparent. I've spent the last hour looking around and I can't seem to figure out how this is done for android. Any help is greatly appreciated!
I haven't worked with Android but on iOS pngs weren't loading for me when I made them in photoshop but when I made them in flash all of a sudden they would work! Try that first :)
Anyways, you want to google something along the line of "pixel arrays android code" you can create an array of each pixel, find an individual color, then make it transparent...
But I really think this is just a GIMP issue and you don't need to go through all of that hassle.
what i can understand from your uncleared words is that you want to display transparent image of a normal image you have . so i would suggest don't do it through programming . create a transparent image through any image editor tool and use it .
if image is dynamic that you cant go in this way so use Matrix and setAlpha . search over net for both the terms
I have 2 images and I want to overlay them and get the same effect as in photoshop's "overlay". Overlay porterduff exist in PorterDuff'd documentation but I guess not for android 2.2.
any idea on how to implement this?
thanks
They have added it to the PorterDuff.Mode enum, but im not sure from what api version, im pretty sure it's >2.2.api doc
You can just use LIGHTEN and darken your dst image to achieve a similar effect :)