Opened 16 years ago

Closed 16 years ago

#2448 closed defect (fixed)

int imageObj.getSize() does not work

Reported by: richf Owned by: unicoletti
Priority: low Milestone:
Component: MapScript-Java Version: 5.0
Severity: minor Keywords:
Cc:

Description

I previously posted this to the mailing list: http://www.nabble.com/-Java-mapscript--int-imageObj.getSize-28-29-does-not-work-to14375813.html

Reposting here.

---

if i have a valid image in an imageObj object:

  • int imageObj.getWidth() returns the expected value
  • int imageObj.getHeight() returns the expected value
  • void imageObj.save(String, null) successfully writes the image to a file
  • byte[] imageObj.getBytes() successfully returns a byte array (whose length matches the size of the file above), containing the proper contents of the image (i can subsequently dump it to a file and verify).

however:

  • int imageObj.getSize() always returns 0

this turns out to not be a big deal. at first i thought i would have to query the size with getSize(), then allocate a byte[] of the appropriate size, then populate the byte[] with getBytes().

however, it is sufficient to just write code like:

  byte[] bytes = img.getBytes();

if img is the imageObj containing the image. it's not necessary to directly query the size, and if i really want to know it, bytes.length will return the proper value.

nevertheless, if i'm properly guessing the intention of imageObj.getSize() [maybe i'm wrong], this seems like a bug to me.

i do notice the following in mapscript/doc/mapscript.txt within the mapserver-5.0.0 distribution:

imageObj Attributes
-------------------

<...>

size : int
    I don't see where this is used.  Anyone?  --SG

<...>

imageObj Methods
----------------

[getSize() is not listed here]

so maybe it's just deprecated.

Change History (2)

comment:1 by richf, 16 years ago

Version: unspecified5.0

comment:2 by unicoletti, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in revision r7188. Also added documentation and this note about its efficiency:

the getSize method is inefficient as it does a call to getBytes and then computes the size of the byte array. The byte array is then immediately discarded. In most cases it is more efficient to call getBytes directly.

Note: See TracTickets for help on using tickets.