Android Question Error (Rotate image)

eng.khalidvb

Member
Licensed User
Longtime User
hi all
I tried to make one option one user click the button it should rotate the image 90 every time user click the button here is my code :
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim img_box As ImageView
    Dim btn_rotate As Button
 
    End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btn_rotate_click(bmp As Bitmap)
If bmp.width>bmp.height Then            'Image is landscape, rotate
      Dim rbmp As RSImageProcessing
      img_box=rbmp.rotateBitmap(bmp, -90)

End If
End Sub

what is the the error here (img_box=rbmp.rotateBitmap(bmp, -90) ?

it show me unknown variable or unknown member: rotateBitmap

What is error means does that mean i can not use rotatebitmap in button if it is what is the code I have to use to rotate image by clicking on button ?
 

eng.khalidvb

Member
Licensed User
Longtime User
See my code it show me error

B4X:
Sub rotate_click(bmp As Bitmap)
Dim rbmp As RSImageProcessing

If bmp.width>bmp.height Then            'Image is landscape, rotate
     
    image_view=rbmp.rotate(bmp,-90)
   
End If
End Sub

image_view=rbmp.rotate(bmp, -90)

what is error in my code.:rolleyes:
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The sub
B4X:
Sub btn_rotate_click(bmp As Bitmap)
  If bmp.width>bmp.height Then
    'Image is landscape, rotate
    Dim rbmp As RSImageProcessing
    img_box=rbmp.rotateBitmap(bmp, -90)
  EndIf
End Sub

The Signature of a click event does not have an Bitmap as parameter!? Where do you got this sub from?
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
I tried to fix the error but I couldnt ? It show me the signature of clcik event dosent support which I am writing it should first initialize the bitmap I dont know how to do that . do you have any comment to push me up ?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
From Post#1 I do not see where you are loading the image into the imageview. What is in Layout#1?
I can only assume:
An imageview called img_box
A button called btn_rotate
Is there anything else? Do you load the image via designer?

Then you could try (not tested):

B4X:
Sub rotate_click
Dim rbmp As RSImageProcessing
Dim bmp as Bitmap
bd.Initialize(directory, Imagefilename)  'load and initalise the bitmap

If bmp.width>bmp.height Then            'Image is landscape, rotate
    bmp = rbmp.Rotate(bmp, -90)
    'Re-size the imageview to bitmap if required
    image_view.width=bmp.width
    image_view.height=bmp.height

    image_view.Bitmap=bmp  'Put bitmap into imageview
 
End If
End Sub

Maybe it can be simplier but its worth a try. Hope it helps.
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
its good thanks but what is the following code :

B4X:
bd.Initialize(directory, Imagefilename)  'load and initalise the bitmap

it show me error here I think I have to initialize bd but I have no idea about how to do that ?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Sorry, a little code mistake. It should be:
B4X:
bmp.Initialize(directory, Imagefilename) 'load and initalise the bitmap

directory is where the bitmap is stored and Imagefilename is the name of the bitmap file eg.

B4X:
bmp.Initialise(File.DirAssets, "image1.jpg")
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
The code I posted will only rotate the bitmap once, from landscape to portrait due to the if statement. I think you are looking at something like this [not tested]:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim img_box As ImageView
    Dim btn_rotate As Button
    Dim rbmp As RSImageProcessing
    Dim bmp as Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    if FirstTime then
        bmp.Initialize(directory, Imagefilename) 'load and initialise the bitmap
    end 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btn_rotate_click
 
    bmp = rbmp.Rotate(bmp, -90)
    'Re-size the imageview to bitmap if required 
    img_box.width=bmp.width
    img_box.height=bmp.height

    img_box.Bitmap=bmp 'Put bitmap into imageview

End Sub
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
I have tried your code but it still show me error, this is my code

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim img_box As ImageView
    Dim btn_rotate As Button
    Dim rbmp As RSImageProcessing
    Dim bmp as Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    if FirstTime then
        bmp.Initialize(File.DirInternal, "csa.jpg") 'load and initialise the bitmap
    end
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btn_rotate_click
    bmp = rbmp.Rotate(bmp, -90)
    'Re-size the imageview to bitmap if required
    img_box.width=bmp.width
    img_box.height=bmp.height

    img_box.Bitmap=bmp 'Put bitmap into imageview

End Sub


it show me error here

B4X:
 bmp = rbmp.Rotate(bmp, -90)


whats wrong ?
 
Upvote 0
Top