Q: Can I use only a part of an Image File and do stuff with it ?

BNig niggemann at uni-wh.de
Thu Oct 1 12:43:28 EDT 2009


Rolf,

there are already some suggestions to your question which are probably very
usable. I just played around with the idea to extract your slices from the
imagedata of the original.
Here is the code works also if the width the original image is not an even
multiple of the width of the slices . It than adds a slice. The sliced image
is placed above the original image.

please beware of linewrapping
-------------------------------------------
on mouseUp
   put 10 into tNoOfImages -- change the number of 'slices' here
   put the imagedata of image "myLongImage" into iD
   put the length of iD into tLengthImageData
   put the height of img "myLongImage" into tHeight
   put the width of img "myLongImage" into tWidth
   put tWidth* 4  into tByteWidth
   put tWidth div tNoOfImages * 4 into tChunkSizeinBytes
   put tWidth div tNoOfImages into tNormalImageWidth
   set the width of the templateimage to tWidth div tNoOfImages
   set the height of the templateimage to tHeight
   set the top of the templateimage to the top of image "myLongImage" 
-tHeight - 20
   set the left of the templateimage to the left of image "myLongImage"
   put 1 into tStartChar
   put "" into tCollect
   -- check if width of original is an even multiple of the 'slices', if not
   -- add an image for the rest of the original image
   put tWidth mod tNoOfImages into tRest
   if tRest <> 0 then 
      put true into tHasARest
      add 1 to tNoOfImages
   end if
   lock screen
   repeat with i = 1 to tNoOfImages
      repeat with j = tStartChar to tLengthImageData step tByteWidth
         put char j to j + tChunkSizeInBytes-1 of id after tCollect
      end repeat
      create image
      set the name of last image to "i" & i -- change name of new images
here
      set the imageData of last image to tCollect
      -- check for additional image in case width is not an even multiple of
'slice'
      if not (tHasARest and i = (tNoOfImages - 1)) then
         -- no additional image
         set the left of the templateImage to the left of the templateImage
+ tNormalImageWidth
      else
         -- additional image (will be last image) of a different width
         put tRest * 4 into tChunkSizeInBytes
         -- a little workaround because changing width changes the left
         put the left of the templateImage into tLeftBeforeChangeOfWidth
         set the width of the templateimage to tRest
         set the left of the templateImage to ( tLeftBeforeChangeOfWidth +
tNormalImageWidth)
      end if
      add tChunkSizeInBytes to tStartChar
      put empty into tCollect
   end repeat
end mouseUp
--------------------------------------
regards
Bernd


Rolf Kocherhans wrote:
> 
> For instance I have an imported Image file (png) 10 pixels high and  
> 100 pixels long.
> 
>  From pixel 1 to 10 ist Picture_one, from pixel 11 to 20 is Picture  
> _two etc.
> 
> Can I the display those 2 respectively 10 pictures individually ?
> 
> Cheers
> Rolf
> 

-- 
View this message in context: http://www.nabble.com/Q%3A-Can-I-use-only-a-part-of-an-Image-File-and-do-stuff-with-it---tp25682504p25701579.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list