I am working on the Android app for the Eyewer Team and I am trying to overlay a Bitmap over another Bitmap before uploading it to my database. I followed many stackoverflow questions and landed on THIS one.
Looks legit but I am facing a bit a difficulty placing the overlay bitmap and its position.
This is where I want it to be placed:
^ Bottom Left Corner
Here's what I have right now:
Bitmap bmOverlay = Bitmap.createBitmap(Bitmap_MainPic.getWidth(), Bitmap_MainPic.getHeight(), Bitmap_MainPic.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(Bitmap_MainPic, new Matrix(), null);
canvas.drawBitmap(overlay_logo, 50,50, null);
How can I position the overlay at the required position using my code or code of your suggestion?
Related
I have this scrollview in which I want to inflate a 1920x1080 background image. If I add it statically via xml, my app lags in animations and general responsiveness. I checked StackOverflow and it's something that is expected to happen because images are uncompressed in memory.
Now, in the same thread linked above, a suggested answer is to use a setBackground function which uses BitmapFactory to dynamically resize and set the image as follows:
fun setBackground(context: Context, view: View, drawableId: Int) {
var bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId)
val width = Resources.getSystem().getDisplayMetrics().widthPixels
val height = Resources.getSystem().getDisplayMetrics().heightPixels
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true)
val bitmapDrawable = BitmapDrawable(context.getResources(), bitmap)
view.background = bitmapDrawable
}
However, as can be seen, this image requires the drawable's ID, which I haven't been able to get. I checked similar questions and found conflicting answers with some saying that it's not possible to get drawable IDs, and other's suggesting some ImageView-related methods that aren't related to my problem (inflating a scrollview). So, can anybody please name a method in Java/Kotlin that allows me to get my drawable image's ID? If that's not possible, can you please suggest another workaround?
Have you tried:
val resID = resources.getIdentifier("drawable_name", "drawable", packageName)
I have a custom WebView. Inside it I've got an image. The WebView is zoomable. I want to reset zoom when I click a button, extract image from there and place inside ImageView.
So far, with the help of x-code I've managed to write this in onClickListener:
while (wv2.zoomOut()){
wv2.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(wv2.getDrawingCache());
bitmapPath = bitmap;
wv2.setDrawingCacheEnabled(false);
new Thread(new Runnable() {
public void run() {
SaveImage(bitmap);
}
}).start();
tstImage.setImageBitmap(bitmap);
}
The WebView zooms out completely, but the Bitmap I get in ImageView is slightly zoomed in. I need to click 1 more time to get the whole bitmap inside the ImageView
I would say that the Javadoc of WebView.getDrawingCache() method explains your problem.
public Bitmap getDrawingCache (boolean autoScale)
...
Note about auto scaling in compatibility mode: When auto scaling is
not enabled, this method will create a bitmap of the same size as this
view. Because this bitmap will be drawn scaled by the parent
ViewGroup, the result on screen might show scaling artifacts. To avoid
such artifacts, you should call this method by setting the auto
scaling to true. Doing so, however, will generate a bitmap of a
different size than the view. This implies that your application must
be able to handle this size.
In your code you simply have to make this change
bitmap = Bitmap.createBitmap(wv2.getDrawingCache(true));
I am using SubsamplingScaleImageView by Dave Morrissey (https://github.com/davemorrissey/subsampling-scale-image-view) to allow users to crop and pan a photo with gestures.
I modified the library to add a tint and a logo to the photo. Now I need to upload the photo to the server. In order to do that I need to somehow extract the photo from the SubsamplingScaleImageView.
I added the following method to the SubsamplingScaleImageView class:
/**
* Capture a photo of the image view
*/
public Bitmap getOutput() {
buildDrawingCache();
Bitmap b1 = getDrawingCache();
Bitmap b = b1.copy(Config.ARGB_8888, true);
destroyDrawingCache();
return b;
}
I am using this method to get the file, resize it to a specific resolution (800x800), and save it to my app's folder.
The problem I noticed is that the extracted photo from the drawing cache depends on the resolution of the device. For example, on my Full HD device I get 1080x1080 photo, which is enough, but on some lower res devices I get resolutions like 480x480 and that is not enough since the image needs to be bigger than that, so the photo gets blurry when I resize it to 800x800.
Is there a way to get the same resolution photo from that image view on all devices?
I want to resize my images (original size is 1080p) but they don't resize properly and I don't know why. The Images just don't have the right size sometimes. On my emulator and my old 800*480 smartphone it works fine but on my nexus 4 with 1280*768 things don't look right. There is no problem reading the right screen resolution. There is just a bug with my resize procedure. Please help me. Heres a Snippet:
private Bitmap bitmap,bitmap1;
private float factor;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displaymetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displaymetrics);
width = displaymetrics.widthPixels;
height = displaymetrics.heightPixels;
factor = (float)height/1080;
Int bitmapheight,bitmapwidth;
bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.picture),(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getwidth() ,(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getHeight(), true);
canvas.drawBitmap(bitmap,.....
In the end the height is not resized to 768/1080*bitmapheight on my nexus and i don't know why. Note everything else works. Mathmatics indicates that the height should be the same on every phone.
These are screenshots of my programm showing the images have not the same height
First image:
Second:
As you can see the Images are not equal in terms of height. On my emulator and my old smartphone they look right. The Images should not touch the bottom but on my nexus 4 they do touch the bottom.
For anyone who is interessted why it didnt work. Finally i found out.
Now
BitmapFactory.decodeResource(getResources(), R.drawable.picture)
not only loads the pictures but also scales it depending on your resolution ( not always just on some resolution) thats why it confused me. I thought it just loads the damn picture. Now how to solve this:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
BitmapFactory.decodeResource(getResources(), R.drawable.picture,opts)
i wanted to create a directory app for a grocery. i already have the floor plan of the place. i just wanted to display it in a view and i want to put some markers/pins/images to it.. i have no idea where to start. someone told me to use bitmap and canvass but i have no idea how to use it as the other tutorials in google is quite vague and hard to understand..
what my app requires:
display a custom map from an image source
enable me to put markers,pins and some images on top of it
A simple way is to use use ImageView:
//make a bitmap from your floorPlanImage, example from file
Bitmap floorPlanImage = BitmapFactory.decodeFile(filePath, options);
//make a mutable bitmap, so it can be changed
Bitmap mutableFloorPlanImage = floorPlanImage.copy(Bitmap.Config.ARGB_8888, true);
//create a canvas to draw on your floorPlanImage
Canvas mCanvas = new Canvas(mutableFloorPlanImage);
//draw a marker or another image on the floorPlanImage, you can position it using left and top //coordinates, in this example both 0
mCanvas.drawBitmap(markerBitmap, 0, 0, null);
//show the resulting bitmap in ImageView
imageView.setImageBitmap(mutableFloorPlanImage);