android-bitmap

How can I save my bitmap correctly for second time?

微笑、不失礼 提交于 2019-12-01 04:26:43
I want to save my bitmap to cache directory. I use this code: try { File file_d = new File(dir+"screenshot.jpg"); @SuppressWarnings("unused") boolean deleted = file_d.delete(); } catch (Exception e) { // TODO: handle exception } imagePath = new File(dir+"screenshot.jpg"); FileOutputStream fos; try { fos = new FileOutputStream(imagePath); bitmap.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.e("GREC", e.getMessage(), e); } catch (IOException e) { Log.e("GREC", e.getMessage(), e); } } it s working fine. But if I want to save different

How to subsample/resize an image like in whatsapp

风格不统一 提交于 2019-11-30 16:43:44
When sending an image through whatsapp, you can see the image you are sending in an imageview scaled very very well for example, i sent two images to my friend size of first image : 1296 pixels X 2304 pixels size of second image : 1920 pixels X 1080 pixels this images are too big therefore whatsapp has to scale them before showing them to me in an imageview size of first image after being scaled by whatapp 333 pixels X 339 pixels size of second image after being scaled by whatsapp 333 pixels X 187 pixels As you can see the width is the same only height differs. i have tried to figure out how

Retrieve bitmap from uri

依然范特西╮ 提交于 2019-11-30 14:48:53
问题 I have included 'share via myApp' option. I inserted following code in the receiving activity class. // Get the intent that started this activity Intent intent = getIntent(); Uri data = intent.getData(); // Figure out what to do based on the intent type if (intent.getType().indexOf("image/") != -1) { // Handle intents with image data ... } What is the next step to retrieve bitmap image. 回答1: As you have already get the Uri. Now you have to pass that Uri in getBitmap() to get bitmap and use

How to subsample/resize an image like in whatsapp

那年仲夏 提交于 2019-11-30 14:25:06
问题 When sending an image through whatsapp, you can see the image you are sending in an imageview scaled very very well for example, i sent two images to my friend size of first image : 1296 pixels X 2304 pixels size of second image : 1920 pixels X 1080 pixels this images are too big therefore whatsapp has to scale them before showing them to me in an imageview size of first image after being scaled by whatapp 333 pixels X 339 pixels size of second image after being scaled by whatsapp 333 pixels

Retrieve bitmap from uri

杀马特。学长 韩版系。学妹 提交于 2019-11-30 11:22:55
I have included 'share via myApp' option. I inserted following code in the receiving activity class. // Get the intent that started this activity Intent intent = getIntent(); Uri data = intent.getData(); // Figure out what to do based on the intent type if (intent.getType().indexOf("image/") != -1) { // Handle intents with image data ... } What is the next step to retrieve bitmap image. As you have already get the Uri. Now you have to pass that Uri in getBitmap() to get bitmap and use that bitmap. Uri imageUri = intent.getData(); Bitmap bitmap = MediaStore.Images.Media.getBitmap(this

OpenGL example to render bitmap to MediaCodec surface

一世执手 提交于 2019-11-30 09:34:04
问题 I am looking for an example on how to render a bitmap to the surface provided by MediaCodec so I can encode and then mux them into mp4 video. The closest well know example I see is this EncodeAndMuxTest. Unfortunately with my limited OpenGL knowledge I have not been able to convert the example to use bitmaps instead of the raw OpenGL Frames it currently generates. Here is the example's Frame generation Method. private void generateSurfaceFrame(int frameIndex) { frameIndex %= 8; int startX,

System error capturing the output of a MediaProjection virtual display to an ImageReader

安稳与你 提交于 2019-11-30 04:21:27
问题 I am working on an application that needs to capture the screen to a bitmap to transmit. I am attempting to use the new Android 5.0 android.media.projection APIs to do the screen capture. The workflow for this API culminates in a call to mediaProjection.createVirtualDisplay("Test Screen", WIDTH, HEIGHT, DPI, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, surface, null, null); In my initial attempt at this capture I sourced the surface object from a SurfaceView. This works correctly; the end

Is there a way to get URI of bitmap without saving it to sdcard?

烂漫一生 提交于 2019-11-29 23:05:14
I am making an app that allows the user to share an image using android intent but how to get that URI of a bitmap without need to saving it to sd card I have used this code that works fine, but I don't need to save this bitmap to sd card private Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "title", null); return Uri.parse(path); } I need to get that URI without saving that bitmap to sd card

How to use RoundedBitmapDrawable

拜拜、爱过 提交于 2019-11-29 20:20:13
Has anyone managed to use RoundedBitmapDrawable ? Correct me if I'm wrong, but to my understanding, it makes a circular image from a regular rectangular image. What I've tried so far is this RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource)) What I tried to achieve: transform any image to a circular image and show it using an ImageView. In case I mixed things up and all that I said is non-sense. Is it possible (or simpler) to do it with any of the new framework? (Android L or new Support Library) alanv You need to set

Distorting an image to a quadrangle fails in some cases on Android

半腔热情 提交于 2019-11-29 18:55:34
问题 I'm using matrix.setPolyToPoly function to transform a selected region (4 corners) of a bitmap into a rectangle and normally it works amazing. But in the next example: The polyToPoly function fails the perspective transform: I have drawn two lines for testing, the lines mark where I want the four selected points. What I'm doing wrong? Thanks! EDIT : I've solved the problem using canvas.drawBitmapMesh, Thanks pskink for your advice!! This is the final code private float[] generateVertices(int