Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Convert BMP image to PNG or JPG in Java without loading the entire image in memory

Posted on November 11, 2022 By

Solution 1 :

Managed to do it using this PNGJ library , written in pure Java so usable in android, and which allows to write PNG files line by line without loading the whole image into memory.

Problem :

I am trying to use a BitmapRegionDecoder to load parts of a large Bitmap image in Android but am stuck because the BMP file format is not supported(only JPG and PNG).
Is is possible to “transcode” a bitmap image into JPG or PNG (compression doesn’t really matter) without loading the entire image into memory?

Something like

FileOutputStream fos = new FileOutputStream(pngFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bmpInputStream.read(buffer)) > 0) {
    // Process bytes to PNG format
    fos.write(buffer, 0, bytesRead);
}

Comments

Comment posted by Gabe Sechan

Why not convert before you put the file on the device (on your machine or on the server)?

Comment posted by tishu

That is not an option the file is picked at runtime by the user

Comment posted by Gabe Sechan

That doesn’t prevent you from pre-encoding it. You just encode all of his choices. Using actual bitmaps, especially for large images, is a really weird choice these days- the file size would be huge.

Comment posted by tishu

That doesn’t make any sense I cannot preencode a file a user picks from his phone at runtime

Comment posted by Gabe Sechan

How did he get the file on his device? Encode it then. It should never be on disk as an actual bitmap. Nothing does bitmap these days.

READ  [FIXED] java - Interstitial advertising (admob) only works once
Powered by Inline Related Posts
Android Tags:android, bitmap, image-conversion, java, jpeg

Post navigation

Previous Post: [FIXED] Xamarin.forms – Trouble behaviour between ListView & keyboard
Next Post: [FIXED] android – two elements in linear layout are packed to center instead of to the sides

Related Posts

[FIXED] React Native Android: How/what is is adding the QUERY_ALL_PACKAGES permission to merged_manifests/release/AndroidManifest.xml Android
[FIXED] Moving data in Android Studio Between Activities Android
[FIXED] android – How to use a variable to change image? Android
[FIXED] java – First Auth Mifare Plus cards Android
[FIXED] java – How to display Images in gridview Android
[FIXED] android – call notifyItemRangeChanged on child adapter of ConcatAdapter doesn’t work Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme