Live Wallpaper; Background

trebun

Member
Licensed User
Longtime User
Hi,

I need help to scale the background images for my live wallpaper.

I take a random flyer from my site with the url:

>> http://.../electronic/fcDownload.php (only some test flyer available)

In the attachments, I uploaded my project (construction area - haha! - not all will work correctly. If all things are done, I will upload and share the code in "Basic4android Share Your Creations"! Promise!)

In the WallpaperService I need to scale the backgroundimage with the right ratio. I need this dynamicly, because not all flyer have the same scaling.

B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
      
   If Flyer.IsInitialized  Then
      
      Engine.Rect.Left = -Engine.CurrentOffsetX 
      Engine.Rect.Top = -Engine.CurrentOffsetY 
      Engine.Rect.Right = -Engine.CurrentOffsetX + Engine.FullWallpaperWidth 
      Engine.Rect.Bottom = -Engine.CurrentOffsetY + Engine.FullWallpaperHeight
      
      Engine.Canvas.DrawBitmap(Flyer, Null, Engine.Rect)

   Else
      Engine.Canvas.DrawColor(Colors.Black)
      Engine.Canvas.DrawText(AResMap.Get("other_placeholder_on_screen"), 120dip, 120dip, Typeface.DEFAULT_BOLD, 30, Colors.White, "LEFT")
   End If
   
   Engine.RefreshAll
End Sub

This works good, but all images on my GNex or N7 are clinched. I think it is a problem with "FullWallpaperHeight" (=1280). But on both devices, I have software buttons they must be subtracted from the "FullWallpaperHeight".

I test it with
B4X:
pScreenHeight=GetDeviceLayoutValues.Height
pScreenWidth=GetDeviceLayoutValues.Width

But I have no Idea with the nice offset x/y. So, please :sign0085:

Regards,
trebun
 

Attachments

  • stretch_wallpaper.jpg
    stretch_wallpaper.jpg
    92.3 KB · Views: 645
Last edited:

Prosg

Active Member
Licensed User
Longtime User
it's the same it show your phone device try

look my SIII samsung

device.jpg


i saw some phone who they tell u when u buy it's a 1280 and in reality it's not :)
 
Last edited:
Upvote 0

trebun

Member
Licensed User
Longtime User
I can't belive it, that this is my problem - I have some troubles with the width not with the height and sure, my GNex have a 1280 pixel display, but the buttons must be subtracted. But I need a generic solution...

Regards,
trebun
 
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
for my wallpaper App, i use 720 x 1280 pictures

not 1280 x 1280 and i only use orientations support as Portrait

it's more simple if you stop support landscape, they could turn the phone but always display portrait
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
Menu Projet => Orientation Support > Portrait


i think it's better to do that

If you want landscape i think u have to do 2 pictures

- One for portrait : 720 x 1280
- One for Landscape : 1280 x 720

and when ..... is portrait then take this picture

else take landscape picture
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
^^
aie

what is the exact mobile you have their device ?

800 x 1280 ?
if it is a 800 x 1280 it's normal cause our pictures is 720 x 1280 (=> we have to change this)

and why it's not locked to portrait ? ! :p

I asked some friends and all of them is locked to portrait (when they move phone no landscape)
 
Last edited:
Upvote 0

trebun

Member
Licensed User
Longtime User
^^
aie

what is the exact mobile you have their device ?

800 x 1280 ?
if it is a 800 x 1280 it's normal cause our pictures is 720 x 1280 (=> we have to change this)

and why it's not locked to portrait ? ! :p

I asked some friends and all of them is locked to portrait (when they move phone no landscape)

Tested with a Galaxy Nexus and a Nexus 7. Screenshots from the Nexus 7.

The most people have deactivated the option to switch between portrait and landscape on the home screen. I have not... ;-)

Regards,
trebun
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
ok you are right somes phones have always black in the right like your image

One friend with a Samsung SII have it

Grrrrr :(

What solution we have to resolve this ?

Another think, I try to know what is the current name of the LiveWallpaper on the phone so when Application start it check that

If Not myLiveWallpaper then open LWPselector
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
I understood what happens:

My images are 720 x 1280 and the phones that have the same ratio see the image in full.

Phones that do not have the same ratio see a black strip on the side because Errel's code keep the ratio in priority.

So three things possible if the phone does not have the same ratio:

- Either put the image centered with transparency => bad
- Or put the picture size by deforming slightly (fit) => maybe the best way
- Either cut the image and zoom

How to code after it is another thing

I'm right because the Nexus is not a 720 x 1280 phone but in reality is 720 x 1184 !!!


Look at this :

B4X:
 Dim origRatio As Float = original.Width / original.Height
   Log ("OrigineRation : " & origRatio)
    Dim targetRatio As Float = TargetX / TargetY
   Log(TargetX & " - " & TargetY)
   Log ("TargetRation : " & targetRatio)
    Dim scale As Float

Errel take a target ratio 1280 x 1280

look the log
For my Samsung SIII
OrigineRation : 0.5625
1280 x 1280
TargetRation : 1

For your Nexus :
1340 - 1196
TargetRation : 1.120401382446289


the only thing to do is get as close as possible of the ratio and fit image width and height maximum like we do in photoshop for exemple
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
For the screen rotation with the tablet someone have a simple solution i give you :

But back to your question: In my case I just work with canvas to draw my stuff. And I don't have to do anything special to draw in landscape mode. When the phone is in portrait mode canvas.getWidth() is the width of my phone, when the phone is in landscape mode canvas.getWidth() is the height of my phone. So I don't have to turn it around or something like this...

Just need to know what is the event to find if it's landscape or portrait
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
  Log ("width:" & GetDeviceLayoutValues.Width & " Height :" & GetDeviceLayoutValues.Height  )
If GetDeviceLayoutValues.Width  > GetDeviceLayoutValues.Height Then
   image =  ResizeImage(image, GetDeviceLayoutValues.Height, GetDeviceLayoutValues.Width )
Else
   image =  ResizeImage(image, GetDeviceLayoutValues.Width , GetDeviceLayoutValues.Height)
End If

i try this script but doesn't work :)

what do you think of my last 2 posts ? do u think i'm right ? (no solution but right :p)
 
Last edited:
Upvote 0

trebun

Member
Licensed User
Longtime User
I'm resigned... ;-)

I think all you say is the right way - but I think its not the right solution to force portrait. I favor to scale the image new on landscape. OK, if you like only a section from the image, but I think its looking better as a only portrait mode...

What is to do: scaling, scaling, scaling... ;-)

B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
  Log ("width:" & GetDeviceLayoutValues.Width & " Height :" & GetDeviceLayoutValues.Height  )
If GetDeviceLayoutValues.Width  > GetDeviceLayoutValues.Height Then
   image =  ResizeImage(image, GetDeviceLayoutValues.Height, GetDeviceLayoutValues.Width )
Else
   image =  ResizeImage(image, GetDeviceLayoutValues.Width , GetDeviceLayoutValues.Height)
End If

i try this script but doesn't work :)

Oh, It works, but your position is wrong. It's not enough to scale the picture to portrait, you must change the position (Rect.Left,.Right,.Bottom,.Top).
 
Last edited:
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
trebun can you try that for me pls with your picture

B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
    If image.IsInitialized AND resized.IsInitialized = False Then
        resized = ResizeImage(image, Engine.FullWallpaperWidth -230, Engine.FullWallpaperHeight)
    End If
    If resized.IsInitialized Then
        Engine.Rect.Left = -(Engine.FullWallpaperWidth - actualImageWidth) / 2
        Engine.Rect.Top = 0
        Engine.Rect.Right = Engine.Rect.Left + Engine.FullWallpaperWidth
        Engine.Rect.Bottom = Engine.FullWallpaperHeight
        Engine.Canvas.DrawBitmap(resized, Null, Engine.Rect)
    End If
    Engine.RefreshAll   
End Sub
 
Upvote 0
Top