The following function will extract an image from a zip file stored anywhere on the filesystem (for as long as the application has access to it).
It will return a bitmap object if the image is found or null otherwise. This function should work in pure java as well with minor alterations (replacing the Log calls with system.outs).
If you you use a wrapper function like this:
you can have a fallback drawable to display if something goes wrong (the above bit is Android specific).
A few things to keep in mind:
It will return a bitmap object if the image is found or null otherwise. This function should work in pure java as well with minor alterations (replacing the Log calls with system.outs).
public Bitmap getBtimapFromZip(final String zipFilePath, final String imageFileInZip){ Log.d(TAG, "Getting image '" + imageFileInZip + "' from '" + zipFilePath +"'"); Bitmap result = null; try { FileInputStream fis = new FileInputStream(zipFilePath); ZipInputStream zis = new ZipInputStream(fis); ZipEntry ze = null; while ((ze = zis.getNextEntry()) != null) { if (ze.getName().equals(imageFileInZip)) { result = BitmapFactory.decodeStream(zis); break; } } } catch (FileNotFoundException e) { Log.e(Constants.TAG, "Extracting file: Error opening zip file - FileNotFoundException: ", e); e.printStackTrace(); } catch (IOException e) { Log.e(Constants.TAG, "Extracting file: Error opening zip file - IOException: ", e); e.printStackTrace(); } return result; }
If you you use a wrapper function like this:
private void loadImage(ImageButton button, String image){ // Use this drawable by default Drawable d = context.getResources().getDrawable(R.drawable.no_image); Bitmap b = getBtimapFromZip("path_to_zip_file", image); if(b != null){ // if the bitmap is not null, load that instead. d = new BitmapDrawable(b); } button.setImageDrawable(d); }
you can have a fallback drawable to display if something goes wrong (the above bit is Android specific).
A few things to keep in mind:
- To get the image out of the zip file you are scanning through all records in the archive sequentially. This could be a performance hit if you have many images.
- If the function returns null but you know that the image is in there, check that you havent accidentally archived the top directory along with the images when creating the zip.
good sample... thanks
ReplyDeletethx a lot!
ReplyDeleteDid you hear there's a 12 word sentence you can tell your man... that will induce intense feelings of love and instinctual attractiveness for you deep inside his chest?
ReplyDeleteBecause deep inside these 12 words is a "secret signal" that triggers a man's impulse to love, cherish and protect you with his entire heart...
12 Words That Fuel A Man's Love Response
This impulse is so built-in to a man's brain that it will drive him to try better than ever before to to be the best lover he can be.
Matter of fact, triggering this dominant impulse is so binding to getting the best ever relationship with your man that the instance you send your man a "Secret Signal"...
...You will instantly notice him expose his heart and mind for you in a way he never expressed before and he'll identify you as the only woman in the universe who has ever truly attracted him.
How to get Thc capsules 10mg?
ReplyDeleteBest kingpen.
Ultimate vape pen.
Where to get vape catridge?
Best place to buy afghan haze.
Ultimate hash.
Best mariejuana near me.
How to get pre rolls?
Reviews about vape catridges.
Where to buy weed cans?