Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Rotate Image By Degrees Angle

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Sep 26, 2020 6:31 am    Post subject: Rotate Image By Degrees Angle Reply with quote

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?



RotateByAngle.JPG
 Description:
Rotate Image By Degree Angle
 Filesize:  48.88 KB
 Viewed:  2144 Time(s)

RotateByAngle.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
ProB1
Advanced Cheater
Reputation: 0

Joined: 20 Jul 2019
Posts: 77
Location: At Home

PostPosted: Sat Sep 26, 2020 6:48 am    Post subject: Reply with quote

how can we add image to black background
_________________
Hitler Hey im Back Smile
Discord: ProB1#0100
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Sep 26, 2020 5:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Sat Sep 26, 2020 6:35 pm    Post subject: Reply with quote

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.



Exm1.JPG
 Description:
 Filesize:  112.35 KB
 Viewed:  2100 Time(s)

Exm1.JPG



abstract-silver.jpg
 Description:
 Filesize:  62.76 KB
 Viewed:  2100 Time(s)

abstract-silver.jpg



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Sep 26, 2020 8:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites