BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-08-2008, 11:48 PM   #1
yairw
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
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, 10:29 PM   #2
yairw
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
Default

are there any RIM engineers on forum, that can offer any help?
Offline  
Old 10-13-2008, 03:13 AM   #3
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
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, 04:47 AM   #4
yairw
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8300
PIN: N/A
Carrier: vodafone
Posts: 15
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 07:54 PM..
Offline  
Old 10-13-2008, 04:58 AM   #5
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
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 04:59 AM..
Offline  
Closed Thread



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

Forum Jump


BEEYUIHF 625Pcs 24Values Aluminum Electrolytic Capacitor Kit 10V-100V 1F-1000uF picture

BEEYUIHF 625Pcs 24Values Aluminum Electrolytic Capacitor Kit 10V-100V 1F-1000uF

$24.99



CBB60 Motor Run Capacitor 450VAC 10uF/20uF/30uF/40uF/50uF 4 Pins CE Standard picture

CBB60 Motor Run Capacitor 450VAC 10uF/20uF/30uF/40uF/50uF 4 Pins CE Standard

$12.99



45/5 MFD uf Round Dual Run Capacitor HVAC AC 45+5 µF 370-440VAC 50/60Hz 5% picture

45/5 MFD uf Round Dual Run Capacitor HVAC AC 45+5 µF 370-440VAC 50/60Hz 5%

$20.99



1PCS - C61 4.5uF+5uF+6uF 5 WIRE 250VAC Ceiling Fan Capacitor UL CERTIFIED picture

1PCS - C61 4.5uF+5uF+6uF 5 WIRE 250VAC Ceiling Fan Capacitor UL CERTIFIED

$7.50



6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF picture

6.3V 10V 16V 25V 35V 50V 100V 400V SMD Aluminum Electrolytic Capacitor 1-1000 UF

$155.59



CBB61 250V  Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF picture

CBB61 250V Capacitor 2 wires 1/2/3/3.5/4/5/6/7/8/9/10/12/15/18/20/24/25/30 UF

$129.95







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