I am trying to create a View of the current display so I can call the following methods to create a Bitmap:
v1.setDrawingCacheEnabled(true);
current = Bitmap.createBitmap(v1.getDrawingCache(), 1686, 136, (631-168), (343-136));
v1.setDrawingCacheEnabled(false);
To create the View I tried this line
View v1 = mCurrentUrlMask.getRootView();
I got the error "Symbol 'mCurrentUrlMask' cannot be resolved."
I'm looking to create a bitmap of a section of the screen, and thoughts you have on this issue are greatly appreciated.
1
View v1 = MainActivity.this.getWindow().getDecorView();//editted
v1.buildDrawingCache();
//your rest of the code.
// you will get a bitmap of the whole screen.
or you could use ViewSnapper
Related
Basically, I'm trying to add an SVG drawable to an ImageView, but I keep getting strange type errors I can't resolve.
// String var "icon" holds the name of the drawable resource
int drawableId = context.getResources()
.getIdentifier(icon, "drawable", MainActivity.PACKAGE_NAME);
// drawableId shows the error:
// 'getDrawable(android.content.Context, int)' in 'android.support.v4.content.ContextCompat' cannot be applied to '(int)'
// I tried using Context instead of ContextCompat, but I got an error about needing API 21
Drawable channelIcon = ContextCompat.getDrawable(drawableId);
// drawableId here shows no error
imageView.setImageResource(drawableId);
Any idea what I'm doing wrong? Basically this is a workaround for needing to use a variable for R.drawable.something
Thanks.
I'm trying to add an SVG drawable to an ImageView
ImageView does not support SVG.
Any idea what I'm doing wrong?
Beyond the aforementioned issue, replace:
Drawable channelIcon = ContextCompat.getDrawable(drawableId);
with:
Drawable channelIcon = ContextCompat.getDrawable(context, drawableId);
I have to add a fragment over an Imageview, but my ImageView goes on top and covers the other views. All this is done in a RelativeLayout.
things must be done dynamically (no xml). I want that my activity has an image, which can be set DYNAMICALLY, and my fragment (added dynamically) should have transparent background, and if this is not true, i can set it to transparent at run time.
This is the code to create the image:
ImageView img=new ImageView(this);
img.setImageResource(imgID);
img.setScaleType(ImageView.ScaleType.CENTER_CROP);
((ViewGroup)findViewById(android.R.id.content)).getRootView()).addView(img);
As you can see, the image works as background, i'm using a ImageView for its scaleType.
Is there a way to do so?
SOLUTION
solved, i added the image to the wrong container.
The function below, however, has been pretty useful. It has been taken from an other answer, and lets a view to get on the back of all the others.
public static void sendViewToBack(View child) {
final ViewGroup parent = (ViewGroup)child.getParent();
if (parent!=null) {
parent.removeView(child);
parent.addView(child, 0);
}
}
I have two activities. One that submits the data and one that shows the submitted data. I am able to add the images to the first activity fine and the data is then stored in a singleton data object with a ArrayList instance called "images".
The problem I have is that when trying to retrieve the images from the image array and display them it crashes the app. I have tried to debug the code and it runs perfectly until you get to the last line:
attachmentLayout.addView(image,imParams);
The Images are stored in the singleton correctly and when you debug it, it shows that they are in fact there.
I tried to figure it out for myself, but I can't find what it is. I am quite new to android programming so help would be much appreciated. I have added my code that tries to get the images below.
if(values.getImage()!=null){
int count = images.size()-1;
for (int x=0;x<=count;x++){
//declare attachments and get image from arraylist<ImageView>
LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachments);
ImageView image;
image = images.get(x);
//set parameters
LinearLayout.LayoutParams imParams =
new LinearLayout.LayoutParams(90,270);
image.setBottom(attachmentLayout.getBottom());
image.setVisibility(View.VISIBLE);
image.isShown();
//add to linear layout
attachmentLayout.addView(image,imParams);
}
}
Edit:
This is the logcat I get when the app restarts after is crashes. I don't believe this is helpful though.
08-24 12:34:18.522 4782-4820/com.example.jules_gribble.test I/Adreno﹕ QUALCOMM build : 065751b,
Build Date : 04/15/15
OpenGL ES Shader Compiler Version: E031.25.03.07
Local Branch :
Remote Branch : quic/LA.BF64.1.2.1_rb2.9
Remote Branch : NONE
Reconstruct Branch : AU_LINUX_ANDROID_LA.BF64.1.2.1_RB2.05.01.00.081.016 + 065751b + NOTHING
Managed to answer my question myself. Turns out it was crashing because I wa overlooking that in the submit activity it was declared
ImageView image = new ImageView(Test.this);
This meant it could not be used in a different activity (Test is the name of the class of the submit activity which will be changed).
To solve this I changed it to
ImageView image = new ImageView(Submitted.this);
where submitted is the name of the submitted activity. I then needed to get the bitmap of the image and set the bitmap to the new imageview.
Bitmap bitmap = ((BitmapDrawable)images.get(x).getDrawable()).getBitmap();
image.setImageBitmap(bitmap);
I found this from HERE.
Hope this will help someone in the future.
I have xml layout which includes a avatar picture a name and a textbox. These are all in one xml file. I would like to add instances these programmically to a linear layout that is nested in a scoll view. Here is my code.
View v = getLayoutInflater().inflate(R.layout.include_message, null);
LinearLayout stallWall = (LinearLayout) v.findViewById(R.id.stallMessages);
R.layout.include_message = My xml
R.id.stallMessages = Linear Layout
I get no errors and i see no items being added.
I would like to read a array and put a include_message in for each message.
First, I would not recommend using x = y = z = a and so on.
It may be working but it's not easy to read and understand.
as codeMagic said, you should use addView() method to achieve this.
here's an example http://androidexample.com/Dynamically_Create_View_Elements__-_Android_Example/index.php?view=article_discription&aid=115&aaid=137
If you are trying to use a layout defined in an xml file, you can user LayoutInflater like this:
View view = getLayoutInflater().inflate(R.layout.yourfile, null);
layout.addView(view);
I am using this project universal-image-loader in order to display in a gridview several images. But I would like to modify these images with some html (for example add ads at the bottom of each images).
I saw the image are displayed by calling imageLoader.displayImage(..), in the method getView of the ImageAdapter.
I don't know what approach is better:
add a step in displayImage(...) in order to create a webview with my image and html and transform this webview in bitmap?
modify the getView of ImageAdapter which will create the webview and add an argument webview in displayeImage()?
...
...
I guess I don't have the choice, I have to use a webview.
Moreover in the method displayImage() of ImageLoader.java, i don't understand where the images are loaded, I guess this is somewhere in this line, but when I am looking in these methods I can't find/understand
ImageSize targetSize = getImageSizeScaleTo(imageView);
String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
cacheKeysForImageViews.put(imageView.hashCode(), memoryCacheKey);
Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);
(How from a string built by an uri and ImageSize we can have a bitmap? where is the image?)
Images are loaded asynchronously. So your code piece is just a top of complex logic. Main work is done in LoadAndDisplayTask class but you don't need to touch it.
For your case you can create own BitmapDisplayer:
create BitmapDisplayer implementation
implement Bitmap display(Bitmap bitmap, ImageView imageView) method
in this method you can process incoming Bitmap as you want
set result Bitmap in ImageView and return result
Set your BitmapDisplayer into configuration.