Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
jgpark
Posts: 9
Registered: ‎07-27-2010
My Device: Not Specified
Accepted Solution

displaying tiff images

Hi there. This is my first post.

 

I'm trying to display a tiff (tagged image file format) in my app. Here's a snippet of code:

 

protected void paint(Graphics graphics) {

            final int imageWidth = Graphics.getScreenWidth();
            final int imageHeight = Graphics.getScreenHeight();
            final EncodedImage image = EncodedImage.getEncodedImageResource("A.tif");
            graphics.drawImage(0, 0, imageWidth, imageHeight, image, 0, 0, 0);

}

 

However, when i run the above i get an IllegalArgumentException during drawImage. I was also unable to open this tiff file from the native image viewer app on the BB. Has anyone successfully written code to display a tiff image file? If so, can you please help.

 

Compiling and running with BB JDE 4.5.0 API on BB 8300 simulator.

 

Cheers.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: displaying tiff images

[ Edited ]

I am about 99% sure tiff is not a supported format on any BlackBerry device at any OS Level. 

 

So I think you will need to convert it to one of the supported formats.  If you are adding the image to the project, this should be painless, I think most paint programs will accept tiff and convert it.  But you probably need the tiff format for some specific reason.  So can you explain why you need these images to be tiff?

 

Edit: I was wrong - see later.

Please use plain text.
New Contributor
jgpark
Posts: 9
Registered: ‎07-27-2010
My Device: Not Specified

Re: displaying tiff images

I'm grabbing them from a remote server as tiffs. So, unfortunately i cannot make the conversion (unless it's possible to make the conversion on the BB?).

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: displaying tiff images

@peter TIFF has been supported since 4.2, it does work with most TIFFs.

 

Is there a message with the exception?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Contributor
jgpark
Posts: 9
Registered: ‎07-27-2010
My Device: Not Specified

Re: displaying tiff images

There is no message. However, if you're privy to the code, then the exception is thrown at:

Graphics.drawImage(int, int, int, EncodedImage, int, int, int) line: 1325

 

Also, i'm unable to open tiff files using the native picture viewing app.

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: displaying tiff images

You say you can't open the TIFF. Do you mean you can't "find" it because it is a resource in a COD file or it is a file on the SDCard/Device memory and it won't open?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Contributor
jgpark
Posts: 9
Registered: ‎07-27-2010
My Device: Not Specified

Re: displaying tiff images

I tried two things:

1) Added tiff as resource and tried to display using code snippet above. This failed (ie: throwing IllegalArgumentException in Graphics.drawImage line: 1325)

2) Copied tiff to sdcard and tried to open using native picture viewer. This also failed.

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: displaying tiff images

  1. After loading the image but before drawImage is the image null?
  2. This might be a bad sign, since the native picture viewer probably uses the same public classes that you are using.

If #1 is not null you can try to get a Bitmap out of the EncodedImage to see if that would work. If you get an error there then that is a deal breaker. Can't really do much when the lowest possible image format (Bitmap) doesn't work.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: displaying tiff images

rcmaniac25 is right, tiff are supported.  My mistake.

 

Having said that, I don't thin they are supported as encoded into the cod file.  Have a look at this from the API:

 

public static EncodedImage getEncodedImageResource(String module,
                                                   String name)Creates an encoded image from provided named resource found in module.
This method looks for the resource in both the .cod file that called this method and any .cod files that it relies on. The resource files are automatically generated by the compiler when a new graphic (PNG, GIF, or, JPG) is added to a project.

So you I suepect you will have to read the file into a byte array amd then use

 

public static EncodedImage createEncodedImage(byte[] data,
                                              int offset,
                                              int length,
                                              String mimeType)Creates an EncodedImage from bytes.
A new instance of the appropriate EncodedImage subclass is returned. If the image format does not match the MIME type, or the image data is otherwise invalid an IllegalArgumentException is thrown. If the MIME type is null then the system will attempt to infer the image type from the image data.

Parameters:
data - The byte array containing the encoded image data. (NOT base64 encoded)
offset - The starting offset of the encoded image data in the array.
length - The length in bytes of the encoded image data, or -1 to indicate the entire array should be used.
mimeType - The MIME type of the image data.
The following MIME types are supported:
•"image/gif"
•"image/png"
•"image/vnd.wap.wbmp"
•"image/jpeg" (supported only on Colour devices)
•"image/jpg" (supported only on Colour devices)
•"image/pjpeg" (supported only on Colour devices)
•"image/bmp"
•"image/tiff"

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: displaying tiff images

That could possibly be it but that doesn't explain why the native picture viewer can't show them when they are files on SDCard/Device memory.

 

Also if rapc doesn't see tiff as a image format it means that it wouldn't convert it to png, so they could open a InputStream to it and read in all the data, if the images are coming from a server then this makes it easier to change where the InputStream comes from and still have it work.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.