ScaleAndroidSplash.ps1 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Scale Android Splash Screens to Multiple Densities
  2. # This script takes a source splash image and scales it to all required Android densities
  3. param(
  4. [string]$SourceSplash = "..\Platforms\Android\Resources\drawable\icon.png", # Using icon as base for now
  5. [string]$OutputBase = "..\Platforms\Android\Resources",
  6. [int]$Width = 480, # Default landscape width for splash
  7. [int]$Height = 320 # Default landscape height for splash
  8. )
  9. Add-Type -AssemblyName System.Drawing
  10. # Define Android density multipliers for splash screens (landscape orientation)
  11. $densities = @{
  12. "drawable-mdpi" = @{ Width = 480; Height = 320 } # 1x
  13. "drawable-hdpi" = @{ Width = 800; Height = 480 } # 1.5x
  14. "drawable-xhdpi" = @{ Width = 1280; Height = 720 } # 2x
  15. "drawable-xxhdpi" = @{ Width = 1600; Height = 960 } # 3x
  16. "drawable-xxxhdpi" = @{ Width = 1920; Height = 1280 } # 4x
  17. }
  18. # Resolve paths
  19. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  20. $sourcePath = Join-Path $scriptDir $SourceSplash
  21. $outputBasePath = Join-Path $scriptDir $OutputBase
  22. Write-Host "Source splash: $sourcePath" -ForegroundColor Cyan
  23. Write-Host "Output base: $outputBasePath" -ForegroundColor Cyan
  24. Write-Host ""
  25. if (-not (Test-Path $sourcePath)) {
  26. Write-Host "Error: Source splash not found at $sourcePath" -ForegroundColor Red
  27. exit 1
  28. }
  29. # Load source image
  30. $sourceImage = [System.Drawing.Image]::FromFile($sourcePath)
  31. Write-Host "Source image size: $($sourceImage.Width)x$($sourceImage.Height)" -ForegroundColor Yellow
  32. Write-Host ""
  33. # Process each density
  34. foreach ($density in $densities.GetEnumerator()) {
  35. $targetWidth = $density.Value.Width
  36. $targetHeight = $density.Value.Height
  37. $outputDir = Join-Path $outputBasePath $density.Key
  38. $outputPath = Join-Path $outputDir "splash.png"
  39. # Create directory if it doesn't exist
  40. if (-not (Test-Path $outputDir)) {
  41. New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
  42. }
  43. Write-Host "Creating splash for $($density.Key): ${targetWidth}x${targetHeight} px" -ForegroundColor Green
  44. # Create new bitmap with solid background color
  45. $newBitmap = New-Object System.Drawing.Bitmap($targetWidth, $targetHeight)
  46. $graphics = [System.Drawing.Graphics]::FromImage($newBitmap)
  47. # Set high quality rendering
  48. $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
  49. $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
  50. $graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
  51. $graphics.CompositingQuality = [System.Drawing.Drawing2D.CompositingQuality]::HighQuality
  52. # Fill background with a color (matching the launcher background color from ic_launcher_background.xml)
  53. $backgroundColor = [System.Drawing.Color]::FromArgb(255, 154, 206, 235) # #9ACEEB
  54. $graphics.Clear($backgroundColor)
  55. # Calculate scaling to fit icon centered in splash screen (maintain aspect ratio)
  56. # Use 40% of splash screen height for icon size
  57. $iconHeight = [int]($targetHeight * 0.4)
  58. $scale = $iconHeight / $sourceImage.Height
  59. $iconWidth = [int]($sourceImage.Width * $scale)
  60. # Center the icon
  61. $x = [int](($targetWidth - $iconWidth) / 2)
  62. $y = [int](($targetHeight - $iconHeight) / 2)
  63. # Draw the scaled icon
  64. $destRect = New-Object System.Drawing.Rectangle($x, $y, $iconWidth, $iconHeight)
  65. $srcRect = New-Object System.Drawing.Rectangle(0, 0, $sourceImage.Width, $sourceImage.Height)
  66. $graphics.DrawImage($sourceImage, $destRect, $srcRect, [System.Drawing.GraphicsUnit]::Pixel)
  67. # Save the image
  68. $newBitmap.Save($outputPath, [System.Drawing.Imaging.ImageFormat]::Png)
  69. # Cleanup
  70. $graphics.Dispose()
  71. $newBitmap.Dispose()
  72. Write-Host " -> Saved to: $outputPath" -ForegroundColor Gray
  73. }
  74. # Cleanup source image
  75. $sourceImage.Dispose()
  76. Write-Host ""
  77. Write-Host "Splash screen scaling complete!" -ForegroundColor Green
  78. Write-Host "All density splash screens have been generated." -ForegroundColor Green