I have tried to use the gpuimage for Android. the issue is not related to gpuimage but it happens at this moment. I'm trying to build an image filter but just using an image as overlay on the original image.
GPUImageColorDodgeBlendFilter tmp = new GPUImageColorDodgeBlendFilter();
tmp.setBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.hipster));
My issue is that I need to access to the file called hipster.png located in res/drawable/hipster.png
I would like to avoid using decodeResource because this image will be always the same and I'm want to avoid using context as the filter class is builtin inside a lib aar and I reuse it in my app.
Any idea ?
I have tried to use the context coming from an activity but it's crashing and I think that context is useless in that case
Thanks
Hi Seb I will tell you how I do it. The only difference is that I use the context, but I pass it as a parameter in certain parts of my code and I don't have any problem.
getResources().getIdentifier(<nameOfImage>, "drawable", getPackageName())
Hope it helps!
Related
I have created an Android library project that i am linking with my Android app. In the drawable folder of the library project, I have added a few images. Now I am trying to access these images from a non-activity class in the same project but they are not being accessed when I try to access them using the following snippet
Drawable drawable=context.getResources().getDrawable(R.drawable.image);
The import of R file is correct and the image id is being generated correctly in the R file. The context is correct. I tried refreshing and cleaning/building the project multiple times but nothing seems to work.
Help!
[Note: Answer copied from here.]
Yes you can if you know the package name of your library.
Resources.getIdentifier(...)
You can do:
getResources().getIdentifier("res_name", "res_type", "com.library.package");
ex:
R.id.settings would be:
getResources().getIdentifier("settings", "id", "com.library.package");
I'm not sure I understand the quest completely (the problem you are having is that the method does not return a drawable?
I'm not sure you about how you are getting the context, but you could try this:
Drawable drawable = ContextCompat(getContext(), R.drawable.image);
If you are storing the context in a variable, you can pass the variable instead of using getContext().
Additionally, the method you are using to get the drawable is deprected, so you shouldn't be using it anymore.
Let me know if it helped you and remember to upvote/select this as correct answer if it did, cheers.
Okay, I've checked, this question never really got a good answer so I'm doing a follow-up and hope someone can help, doing an Imageview is easy (just a drag & drop and then some styling & referencing) but how do we really put a gif in an activity THE EASY WAY. Let's say our gif's name is mygif1 and it's in the resources folder under raw. I'd like it to play in my activity called activity1 in loop while it lasts, Should I create a class especially for that gif or can I make all the references in activity1, what type do I use in Layout to reference it? Can I make it painless or do i have to create 5 classes and 500 lines of code? An example with this data would be much appreciated :)
See this gist gif utils, use it like below:
final ImageView v = ((ImageView)findViewById(R.id.gif_test));
AnimatedGifDrawable drawable = new AnimatedGifDrawable(getResources()
.openRawResource(R.drawable.gif_image), null, 3);
drawable.setOneShot(false);
v.setImageDrawable(drawable);
I have developed a little application using GPUImage. I set a filter to GPUImageView and the image changed, but how can I remove the filter to see the real image?
Assuming you're using the following library: https://github.com/CyberAgent/android-gpuimage
Checking at the source code of the abovementioned library you should simply be able to do something like this:
GPUImageView v ...
v.setFilter(new GPUImageFilter(GPUImageFilter.NO_FILTER_VERTEX_SHADER, GPUImageFilter. NO_FILTER_FRAGMENT_SHADER));
which is equivalent to
v.setFilter(new GPUImageFilter());
Since the class has an alternative constructor:
public GPUImageFilter() {
this(NO_FILTER_VERTEX_SHADER, NO_FILTER_FRAGMENT_SHADER);
}
with the default values already applied.
Let me know if that worked out for you.
i am creating an app to get Uri of an image and do some processing on the image on Java class.
once i got the URi, i will pass it to a java class to get the image into bitmap and process it. my question is,
can MediaStore.Images.Media.getBitmap(); be use in normal java class?
if cant, is there other way to convert my Uri into Bitmap?
cuz from wat i know passing bitmap around will cause out of memory error.
Yes, you can use it, whilst working on Android Application.
I want to load an asset and the only way I can see to do that is with
Context.Assets.Open();
I don't see a way to get access to Context without passing it around. I really don't want to pass it around
To answer my own question:
Application.Context.Assests.Open()
is what I was looking for. For some reason I just couldn't see it.