Ask a Question related to Macromedia Director Lingo, Design and Development.
-
protocol_droid webforumsuser@macromedia.com #1
Imaging Lingo: Bicubic Sampling
I wanted to resize a bitmap member (to later resave on disk), but thought I might have to use an Xtra to do what I need. I'm not big into Xtras, so I took a PHP Function (specifically for GD 1.0) and translated it into lingo, and added a few notes.
It's probably not the fastest way to do it, but, I thought someone might also find this handy.
(Look out for long lines!)
on ImageCopyResampleBicubic (src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
----------------------------------------------------------
-- FUNCTION: Copys a portion of an image, and resizes it.
-- Averages colors to retain image quality.
----------------------------------------------------------
-- RETURNS: newImage (of ilk #image)
----------------------------------------------------------
-- ACCEPTS:
--
-- src_image => Original Image, i.e. member("My Flower Picture").image
-- dst_x => X position of where copy will be start being placed on newImage
-- dst_y => Y position of where copy will be start being placed on newImage
-- src_x => X position of area to start copying from
-- src_y => Y position of area to start copying from
-- dst_w => Width of copied portion onto newImage
-- dst_h => Height of copied portion onto newImage
-- src_w => Width of resulting newImage
-- src_h => Height of resulting newImage
----------------------------------------------------------
-- EXAMPLE:
--
-- -- Copy Entire Image into a smaller image, 40% the size
-- bigFlower = member("flower").image
-- pct = [bigFlower.width * .4,bigFlower.width * .4]
-- littleFlower = ImageCopyResampleBicubic(bigFlower, 0, 0, 0, 0, pct[1], pct[2], bigFlower.width, bigFlower.height)
----------------------------------------------------------
-- ORIGIN:
-- User comments @ [url]http://www.php.net/manual/en/function.imagecopyresized.php[/url]
-- Originally by: daniel dot stankewitz at onvista dot de
newImage = image( (dst_w + dst_x), (dst_h + dst_y), src_image.depth )
rX = src_w / dst_w
rY = src_h / dst_h
w = 0
repeat with y = dst_y to dst_h
ow = w
w = integer((y + 1) * rY)
t = 0
repeat with x = dst_x to dst_w
r = 0
g = 0
b = 0
a = 0
ot = t
t = integer((x + 1) * rX)
repeat with u = 0 to (w - ow)
repeat with p = 0 to (t - ot)
cA = src_image.getPixel(ot + p, ow + u)
r = r + cA.red
g = g + cA.green
b = b + cA.blue
a = a + 1
end repeat
end repeat
newImage.setPixel(x,y,rgb(integer(r / a), integer(g / a), integer(b / a))) -- ImageSetPixel (dst_img, x, y, ImageColorClosest (dst_img, r / a, g / a, b / a));
end repeat
end repeat
return newImage
end
protocol_droid webforumsuser@macromedia.com Guest
-
Imaging Lingo issues- PLEASE HELP
Hi, Im having a major problem getting some simple features ready with imaging lingo, and I need help!! 1st feature: Select an X-ray, it pops up... -
imaging lingo
hey, Is there a way to resize a member's image without it getting distorted. Director is a vector based program, so when you resize a sprite(with... -
imaging lingo (zoom + pan)
Hi, I need to make a zoom & pan feature for a small part of the stage. There are a few problems: 1) I can make the image expand and contract, but... -
text over bmp w/ imaging lingo
I'm using imaging lingo to compose some text over a bitmap. The result i scored was quite good --until i set the composed member on stage. The... -
Imaging lingo challenge...
Okay, I was asking this in the Photoshop newsgroups, but not getting much luck, so I wonder if there's a coding-approach I can take to this. I have... -
Andrew Morton #2
Re: Imaging Lingo: Bicubic Sampling
The default for copyPixels (i.e. using #copy ink) is to resample the image. Even
if MM didn't document it. And it does a very good job when shrinkifying
pictures.
Andrew Morton
Andrew Morton Guest
-
hairybobby webforumsuser@macromedia.com #3
Re: Imaging Lingo: Bicubic Sampling
hi droid,
how about checking out the copypixels function. if you are wanting to resize downwards then it works a treat.
on startmovie me
new(#bitmap,member 3)--create a new member at cast member 3
newimage=image(100,100,32)-- create a new image
newimage.copypixels(member(2).image,newimage.rect, member(2).rect)
member(3).image=newimage --sets the image of member 3 as newimage
end
this copies member 2 into member 3. Resizing upwards might be a different matter as that involves skill . For that I'd probably use photoshop.
HAIRYBOBBY - why didn't I choose a really cool name like the vulcanpimp
[url]http://www.geocities.com/hairybobby2000[/url]
Photography section
[url]http://www.geocities.com/hairybobby2000/px1.html[/url]
Photoshop section
[url]http://www.geocities.com/hairybobby2000/photo1.html[/url]
hairybobby webforumsuser@macromedia.com Guest



Reply With Quote

