View previous topic :: View next topic |
Author |
Message |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sat Sep 26, 2020 6:31 am Post subject: Rotate Image By Degrees Angle |
|
|
Hi, there. To rotate 90 degree or flip horizontal / vertical image using CE Lua script is easy, but how to rotate an image at center(x,y) position by degree angle given?.
In VB/C# more easy by using system drawing image transform. Or, GDI, etc. But I want to do this using pure CE Lua script (or Lazarus free pascal style). So, here is a work script example.
Code: | if f then f.destroy() end
f = createForm()
f.Position = 'poScreenCenter'
f.setSize(300,600)
f.Caption = 'CRDR'
f.Tag = 0
Image1 = createImage(f)
Image1.setPosition(0,0)
Image1.Picture.loadFromStream(findTableFile('thumb.png').Stream)
Image1.Width = 300
Image1.Height = 300
Image1.Stretch = true
Image1.Transparent = true
Image2 = createImage(f)
Image2.setPosition(0,300)
Image2.Width = 300
Image2.Height = 300
--Image2.Stretch = true
Image2.Transparent = true
function Rotate(img, angle)
local angRad = angle*math.pi/180
local cosine = math.cos(angRad)
local sine = math.sin(angRad)
local width_out = math.ceil(img.width * math.abs(cosine) + img.height * math.abs(sine))
local height_out = math.ceil(img.width * math.abs(sine) + img.height * math.abs(cosine))
local out = createImage(self)
out.width = width_out
out.height = height_out
out.Canvas.Clear()
out.Picture.Bitmap.Canvas.TransparentColor = 0
out.Picture.Bitmap.Canvas.Clear()
local x_center_image = img.width / 2
local y_center_image = img.height / 2
local x_center_outImage = out.width / 2
local y_center_outImage = out.height / 2
for y = 0, height_out-1 do
for x = 0, width_out-1 do
local outX = math.ceil(cosine*(x-x_center_outImage)+sine*(y-y_center_outImage)+x_center_image)
local outY = math.ceil(-sine*(x-x_center_outImage)+cosine*(y-y_center_outImage)+y_center_image)
if outX >= 0 and outX < img.width and outY >=0 and outY < img.height then
out.Canvas.setPixel(x, y, img.Picture.Bitmap.Canvas.getPixel(outX,outY))
end
end
end
Image2.Picture = out.Picture
Image2.Stretch = true
out.Destroy()
end
f.Show()
Rotate(Image1, 45) |
Questions:
1. How to eliminate 'the black part color' on the result?
2. By using bitmap pixels control, the process become extreme slow. How to make it fast?.
3. Is there any other way to do this?. May be using copyRect and draw?
Description: |
Rotate Image By Degree Angle |
|
Filesize: |
48.88 KB |
Viewed: |
2144 Time(s) |

|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
ProB1 Advanced Cheater
Reputation: 0
Joined: 20 Jul 2019 Posts: 77 Location: At Home
|
Posted: Sat Sep 26, 2020 6:48 am Post subject: |
|
|
how can we add image to black background
_________________
Hitler Hey im Back
Discord: ProB1#0100 |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sat Sep 26, 2020 5:35 pm Post subject: |
|
|
ProB1 wrote: | how can we add image to black background |
Create a panel with black color and add an image to the panel.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1522
|
Posted: Sat Sep 26, 2020 6:35 pm Post subject: |
|
|
Let me just state this; Windows 10 and the code works fine.
The only problem is that it gives the result a little late and it freezes.
Description: |
|
Filesize: |
112.35 KB |
Viewed: |
2100 Time(s) |

|
Description: |
|
Filesize: |
62.76 KB |
Viewed: |
2100 Time(s) |

|
_________________
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sat Sep 26, 2020 8:15 pm Post subject: |
|
|
I have give warns, as on original first post.
Quote: | 2. By using bitmap pixels control, the process become extreme slow. How to make it fast?.
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
 |
|