0

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(); 
7
  • I'm not an expert on the topic but you could try using BitmapFactory.decodeResource(..., BitmapFactory.Options) where you make sure that Options.inScaled is set to false. Commented Jan 6, 2013 at 13:24
  • Try visit.getWidth() and visit.getHeight(), to see if the bitmap is stretched or if it happens later. Commented Jan 6, 2013 at 14:10
  • visit.jpg is 339x22,but visit.getWidth() shows 452 and visit.getHeight() shows 29, why ? Commented Jan 6, 2013 at 14:27
  • That is somehow strange. I tried to reproduce your situation by quickly prototyping a similar app. The watermark appears OK on my side, without stretch. Link: img801.imageshack.us/img801/4971/savedimage.jpg (Penguins is the watermark) Commented Jan 6, 2013 at 14:41
  • @AndyRes , which one you tried the File-Bitmap or BitmapFactory ? as i mentioned using File-Bitmap, is giving proper result. Commented Jan 6, 2013 at 15:48

1 Answer 1

1

EDIT: I forgot an easier way, put the images in /res/drawable-nodpi folder.

Android will automatically scale the resource image depending on your screen density. The default drawable folder correspond to the mdpi so if you have a hdpi device the image will be scaled up. You can put the image into the /res/raw/ folder then open it like:

Uri imageUri = Uri.parse("android.resource://your.app.package/raw/visit"); InputStream is = context.getContentResolver().openInputStream(imageUri); Bitmap bmp = BitmapFactory.decodeStream(is, null, opts); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.