1. bitmap cropping (was: )
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Mar 10, 1998
- 663 views
At 17:56 9/03/98 +1300, you wrote: >How do I clip an image that has been loaded by read_bitmap()? >I am trying to fit a large picture into a 533x370 area. >I have the following section to clip the width that doesn't work. >It does run all of the lines, and length(tmp_img) is 800 > >if length(tmp_img) > 533 then > tmp_img1=tmp_img[1..533] > tmp_img=tmp_img1 >end if > display_image({11,49},tmp_img1) > You're on the right track, however you're trying to access the birmap as if it were one dimensional (as against two). "tmp_img[1..533]" refers to the first 533 elements of the sequence, which in this case is the first 533 horizontal lines. You want the first 533 pixels on each of the first 370 lines. try this: function crop(sequence bitmap,sequence dim) sequence temp temp=repeat(repeat(0,dim[1]),dim[2]) if dim[1]>length(bitmap[1]) then dim[1]=length(bitmap[1]) end if for x=1 to length(bitmap) do -- Number of horizontal lines if x>dim[2] then exit end if temp[x]=bitmap[x][1..dim[1]] -- first n pixels of line x end for return temp end function tmp_img1=crop(tmp_img,{533,370}) This function should return a bitmap of the specified size regardless of the size of the bitmap passed to it. In the case of a smaller bitmap than the requested size, a black border will be inserted. The "If dim[1]>length(bitmap[1])" line is there in case a narrower bitmap than the target width is passed. It lowers the target width 'dim[1]' to the width of the bitmap ('length(bitmap[1])' being the length of the top line of the bitmap) *after* generating the blank target sequence (temp=repeat...). WARNING - Untested code - I just typed it into Eudora (should work though) Hope this helps. Graeme.