I m taking screenshot of android screen and Draw another image on captured image (watermark) using canvas.drawBitmap,
it all giving proper result when i copy the Watermark(another image - say visit.jpg) image on SD card, the captured image has width 500pixel, where visit.jpg has width- 339pixels,
File file = new File( Environment.getExternalStorageDirectory() + "/visit.jpg"); Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); but i dont want to copy the watermark image into sdcard, i want the image from res folder should get draw on captured image, so i used
Bitmap visit = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.visit); and draw on canvas and saved, it get saved, but the Watermark image(visit.jpg) gets stretch and its size gets larger than 339pixels. why ?
my code is :
View v1 = findViewById(android.R.id.content).getRootView(); v1.setDrawingCacheEnabled(true); Bitmap screenshot = Bitmap.createBitmap(v1.getDrawingCache()); Bitmap cropimg = Bitmap.createBitmap(screenshot, 50, 0, screenshot.getWidth()-100, 592); v1.setDrawingCacheEnabled(false); Bitmap Rbitmap = Bitmap.createBitmap(cropimg).copy(Config.ARGB_8888, true); Bitmap visit = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.visit); // image accessed from drawable Canvas canvas = new Canvas(Rbitmap); File file = new File( Environment.getExternalStorageDirectory() + "/visit.jpg"); // the image copied on sd card Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); canvas.drawBitmap(visit, 0, 570, null); // if i put myBitmap instead of visit i.e. canvas.drawBitmap(myBitmap, 0, 570, null); then visit.jpg image gets draw properly with 339pixel width without strtch canvas.save();
BitmapFactory.decodeResource(..., BitmapFactory.Options)where you make sure thatOptions.inScaledis set to false.visit.getWidth()andvisit.getHeight(), to see if the bitmap is stretched or if it happens later.