Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus Player | Nexus 9
test: Reply
 
LinkBack Thread Tools
Old April 19th, 2012, 08:26 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2010
Location: nyc
Posts: 11
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default BitmapFactory : "decode returned false" for internal image files extracted from zip

Hello again all,

Need to display images downloaded and extracted from a zip into the "/files" directory of the app. the images are getting in there properly as far as i can tell - i am able to extract them from the emulator and view/open them from my desktop. but every attempt, every variation of code i have found and tried so far has failed (Tag: skia / Text: --- decoder->decode returned false).

My latest construct, which does work for image files downloaded separately and uncompressed :

Code:
String imgFile = new File(getFilesDir(), "myImage.jpg").getAbsolutePath();
			
			ImageView myImageView = new ImageView(this); 
			Bitmap bm = null;
			try{
				
				bm = BitmapFactory.decodeFile(imgFile);
				myImageView.setImageBitmap(bm);
				
			} finally{
			
				mainLayout.addView(myImageView);
			}


And here is the construct i am using to handle the zip extraction. I assume this is where the problem lies but i am clueless as to what i could possibly do differently and to what effect:


Code:
ZipInputStream zis = new ZipInputStream(fis);
				
		BufferedInputStream in = new BufferedInputStream(zis, 8192);
		
		ZipEntry ze;
			
				
		while ((ze = zis.getNextEntry()) != null){
									
			File dest_file = new File(getFilesDir(), ze.getName());
						
			FileOutputStream fout = new FileOutputStream(getFilesDir() + "/" + ze.getName());

			BufferedOutputStream out = new BufferedOutputStream(fout, 8192);
						 
			byte b[] = new byte[1024];
			int n;
			while ((n = in.read(b,0,1024)) >= 0) {

				out.write(b,0,n);
			}
						 
						 
			for (int c = zis.read(); c != -1; c = zis.read()) { 

				fout.write(c); 
			}
					    
						
			zis.closeEntry();
			fout.close();
					       	
		}
			
	
		zis.close();
		fis.close();


At a terrible standstill here. Appreciate any solutions/suggestions.

Advertisements
kadmos is offline  
Reply With Quote
sponsored links
Old April 19th, 2012, 08:59 AM   #2 (permalink)
Member
 
Join Date: Apr 2012
Location: London
Posts: 102
 
Device(s): ZTE Skate, Ainol Novo7 Aurora
Carrier: Not Provided

Thanks: 2
Thanked 24 Times in 23 Posts
Default

It looks like you might be reading and writing the same data twice.. Do you really need that for loop?

I'm also not sure if you should be wrapping the ZipInputStream in a BufferedInputStream like that.. Presumably getNextEntry() seeks within the ZipInputStream to the start of the next file. I don't know if the BufferedInputStream will take the stream position from the underlying ZipInputStream, or if it maintains its own position in the stream. Try wrapping the FileInputStream you pass into the ZipInputStream constructor with a BufferedInputStream instead.

-George
GeorgeN is offline  
Reply With Quote
Old April 19th, 2012, 08:54 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2010
Location: nyc
Posts: 11
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the response GeorgeN. Someone else also responded to this on another forum and posted the ZipInputStream example code from the Developers Guide. i still had to figure out how to actually write the file from the bytes array but now this works perfectly:

Code:
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
try {
	ZipEntry ze;
	while ((ze = zis.getNextEntry()) != null) {
							
		Log.i(DEBUG_TAG, "file: " + getFilesDir() + "/" + ze.getName());
							
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int count;
		while ((count = zis.read(buffer)) != -1) {
			baos.write(buffer, 0, count);
		}
		String filename = ze.getName();
		byte[] bytes = baos.toByteArray();

	        FileOutputStream fout = new FileOutputStream(getFilesDir() + "/" + filename);
		fout.write(bytes);
		fout.close();
		}
} finally {
	zis.close();
	fis.close();						
}


also my apologies for posting this in the wrong forum - mods please move (or remove) as you see fit.
kadmos is offline  
Last edited by kadmos; April 20th, 2012 at 01:03 AM.
Reply With Quote
Reply
Tags
bitmapfactory, decode returned false, image, images, zip


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:10 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.