BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-09-2008, 12:48 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default loading an image from the SD card

Please Login to Remove!

Hi,
I've written code that loads images from the blackberry sd card and displays thumbnails of them. In the emulator everything works fine. But on the device (8300 v4.5.0.18 Platform 2.7.0.43) the same code doesn't work. The code is below:
File Search Code:-
Code:
private void searchDirectory(Enumeration en, String path) {
        if (path == null || "".equals(path)) {
            path = "file://localhost/";
        }
        try {
            while (en.hasMoreElements() && !processCompleted) {
                String fileName = (String) en.nextElement();
                FileConnection node = (FileConnection) Connector.open(path + fileName);
                if (node.exists()) {
                    if (node.isDirectory()) {
                        searchDirectory(node.list(), node.getURL());
                    } else if (isImageFile(fileName)) {
                        Logger.error("FileSearchTask.searchDirectory " + path + fileName + " : " + node.canRead());
                        Bitmap bitmap = ImageUtil.createThumbnail(node.openInputStream(),
                                ImageInformationHolder.getFileType(fileName));
                        imageCallback.imageCallback(new ImageInformationHolder(node.getURL(),
                                fileName, bitmap));
                    }
                }
                if (node != null) {
                    node.close();
                }
            }

        } catch (Exception ex) {
            Logger.error("FileSearchTask.searchDirectory", ex);
        }
    }
Image load Code:-
Code:
public static Bitmap createThumbnail(InputStream input, String type) {
		if (input == null) {
			return null;
		}
		try {
		    Enumeration en = EncodedImage.getSupportedMIMETypes();
		    while(en.hasMoreElements()) {
		        Logger.error(" Supported Image Types " + (String)en.nextElement());
		    }
			float y = MAX_HEIGHT;
			EncodedImage bitmap = null;
			int available = input.available();
            byte[] data = new byte[available];
            input.read(data, 0, available);
			Logger.error(" ImageUtil.createThumbnail : LOADING BITMAP " + type);
			bitmap = EncodedImage.createEncodedImage(data, 0, data.length); // not working on device tryed bitmap = EncodedImage.createEncodedImage(data, 0, data.length, type); also doesn't work
			Logger.error(" ImageUtil.createThumbnail : LOADED BITMAP");
			if (bitmap.getHeight() > y) {
				float x = (bitmap.getHeight() / y) * 100.0f;
				Float scalePer = new Float(x);
				int divisor = Fixed32.toFP(100);
	
				/**
				 * Change this number, < 100 makes the image bigger by percentage.
				 * i.e. 90 makes the image 110% normal size. By increasing, you will
				 * reduce the image size, e.g. 110 makes the image 90% normal size.
				 */
				int multiplier = Fixed32.toFP(scalePer.intValue());
	
				int fixedX = Fixed32.toFP(1);
				/** First, divide the image scale by 100. */
				fixedX = Fixed32.div(fixedX, divisor);
				/** Now, multiply the image scale by the multiplier. */
				fixedX = Fixed32.mul(fixedX, multiplier);
	
				int fixedY = Fixed32.toFP(1);
				fixedY = Fixed32.div(fixedY, divisor);
				fixedY = Fixed32.mul(fixedY, multiplier);
				Logger.error(" ImageUtil.createThumbnail : SCALING BITMAP x=" + fixedX + " y=" + fixedY );
				bitmap = bitmap.scaleImage32(fixedX, fixedY);
				Logger.error(" ImageUtil.createThumbnail : SCALED BITMAP");
			}
			input.close();
			return bitmap.getBitmap();
		} catch (Exception e) {
		    Logger.error("ImageUtil.createThumbnail", e);
			return null;
		}
	}
I get the following errors:-
[ERROR] 9/10/2008 15:10 : FileSearchTask.searchDirectory file://localhost/SDCard/BlackBerry/pictures/IMG00006.jpg : true
[ERROR] 9/10/2008 15:10 : Supported Image Types image/x-rpi
[ERROR] 9/10/2008 15:10 : Supported Image Types image/jpg
[ERROR] 9/10/2008 15:10 : Supported Image Types image/jpeg
[ERROR] 9/10/2008 15:10 : Supported Image Types image/vnd.wap.wbmp
[ERROR] 9/10/2008 15:10 : Supported Image Types image/x-rwi
[ERROR] 9/10/2008 15:10 : Supported Image Types image/bmp
[ERROR] 9/10/2008 15:10 : Supported Image Types image/vnd.rim.png
[ERROR] 9/10/2008 15:10 : Supported Image Types image/gif
[ERROR] 9/10/2008 15:10 : Supported Image Types image/tiff
[ERROR] 9/10/2008 15:10 : Supported Image Types image/pjpeg
[ERROR] 9/10/2008 15:10 : Supported Image Types image/png
[ERROR] 9/10/2008 15:10 : Supported Image Types image/x-rdi
[ERROR] 9/10/2008 15:10 : Supported Image Types image/x-rgi
[ERROR] 9/10/2008 15:10 : ImageUtil.createThumbnail : LOADING BITMAP image/jpg
[ERROR] 9/10/2008 15:10 : ImageUtil.createThumbnail : java.lang.IllegalArgumentException: null

[ERROR] 9/10/2008 15:10 : FileSearchTask.searchDirectory file://localhost/store/samples/contacts/BlueDress.png : true
[ERROR] 9/10/2008 15:10 : FileSearchTask.searchDirectory : net.rim.device.api.system.ControlledAccessExceptio n: null

Any help is greatly appreciated.
Offline  
Old 10-12-2008, 11:29 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

are there any RIM engineers on forum, that can offer any help?
Offline  
Old 10-13-2008, 04:13 AM   #3 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, never seen a RIM guy here, use RIM's official forum to meet them...

I assume that you are using the correct JDE version. Have you signed your application before loading on the device?
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-13-2008, 05:47 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using JDE 4.3 and I signed the cod before uploading it on to the device.
I think I've solved the problem, the byte array isn't loading so I've converted the InputStream into a ByteArrayOutputStream and then created the byte array using the ByteArrayOutputStream. Of course the java.lang.IllegalArgumentException was very helpful in pointing to the problem NOT.

Last edited by yairw : 10-13-2008 at 08:54 PM.
Offline  
Old 10-13-2008, 05:58 AM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

normally it should work with your original code.
Attach your device to the JDE debugger and step through the code - maybe it helps more

I'm doing it the same way:
Code:
			FileConnection fc = (FileConnection) Connector.open("file:///" + filePath);
			if (fc.exists()) {
				byte[] image = new byte[(int) fc.fileSize()];
				InputStream inStream = fc.openInputStream();
				inStream.read(image);
				inStream.close();

				EncodedImage eimg = EncodedImage.createEncodedImage(image, 0, -1);
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)

Last edited by Ivanov : 10-13-2008 at 05:59 AM.
Offline  
Closed Thread


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

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





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.