iOS Question Resize image error

gerredtor

Active Member
Licensed User
Hello i try to resize a image but i become a error.

Here my Code:

B4X:
Sub ResizeImage (Image As Bitmap, Width As Int, Height As Int) As Bitmap
    Dim PhotoCanvas As Canvas
    Dim PhotoPanel As Panel
    Dim PhotoView As ImageView
    Dim NewImage As Bitmap
           
    PhotoPanel.Initialize("")
    PhotoPanel.Width = Width / 2
    PhotoPanel.Height = Height / 2
  
    PhotoView.Initialize("")
    PhotoView.Bitmap = Image
  
    PhotoPanel.AddView(PhotoView,0,0,Width / 2,Height / 2)

    PhotoCanvas.Initialize(PhotoPanel)
    NewImage = PhotoCanvas.CreateBitmap

    Return NewImage
End Sub

And here the Error

B4X:
Application_Start
Error occurred on line: 320 (Main)
Object was not initialized (UIImage)
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Lulaj                -[B4IObjectWrapper object] + 200
  Lulaj                -[B4IImageViewWrapper setBitmap:] + 112
  Lulaj                -[b4i_main _createlistitem:::] + 1912
  Lulaj                -[b4i_main _setuppage1] + 3936
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 292
  Lulaj                +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
Lulaj                -[B4IShell runMethod:] + 574
Lulaj                -[B4IShell raiseEventImpl:method:args::] + 1998
Lulaj                -[B4IShellBI raiseEvent:event:params:] + 1442
Lulaj                __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 1532
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1590
CoreFoundation       CFRunLoopRunSpecific + 516
CoreFoundation       CFRunLoopRunInMode + 108
GraphicsServices     GSEventRunModal + 160
UIKit                UIApplicationMain + 144
Lulaj                main + 108
libdyld.dylib        <redacted> + 2
)
Application_Active



Line 320 is The return

and Here is my Use:
    iv.Bitmap = ResizeImage(LoadBitmap(File.DirAssets, "test.png"),Width,40)
 

tufanv

Expert
Licensed User
Longtime User
I think you did not initialize an imageview
Hello i try to resize a image but i become a error.

Here my Code:

B4X:
Sub ResizeImage (Image As Bitmap, Width As Int, Height As Int) As Bitmap
    Dim PhotoCanvas As Canvas
    Dim PhotoPanel As Panel
    Dim PhotoView As ImageView
    Dim NewImage As Bitmap
          
    PhotoPanel.Initialize("")
    PhotoPanel.Width = Width / 2
    PhotoPanel.Height = Height / 2
 
    PhotoView.Initialize("")
    PhotoView.Bitmap = Image
 
    PhotoPanel.AddView(PhotoView,0,0,Width / 2,Height / 2)

    PhotoCanvas.Initialize(PhotoPanel)
    NewImage = PhotoCanvas.CreateBitmap

    Return NewImage
End Sub

And here the Error

B4X:
Application_Start
Error occurred on line: 320 (Main)
Object was not initialized (UIImage)
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Lulaj                -[B4IObjectWrapper object] + 200
  Lulaj                -[B4IImageViewWrapper setBitmap:] + 112
  Lulaj                -[b4i_main _createlistitem:::] + 1912
  Lulaj                -[b4i_main _setuppage1] + 3936
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 292
  Lulaj                +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
Lulaj                -[B4IShell runMethod:] + 574
Lulaj                -[B4IShell raiseEventImpl:method:args::] + 1998
Lulaj                -[B4IShellBI raiseEvent:event:params:] + 1442
Lulaj                __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 1532
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1590
CoreFoundation       CFRunLoopRunSpecific + 516
CoreFoundation       CFRunLoopRunInMode + 108
GraphicsServices     GSEventRunModal + 160
UIKit                UIApplicationMain + 144
Lulaj                main + 108
libdyld.dylib        <redacted> + 2
)
Application_Active



Line 320 is The return

and Here is my Use:
    iv.Bitmap = ResizeImage(LoadBitmap(File.DirAssets, "test.png"),Width,40)
 
Upvote 0

gerredtor

Active Member
Licensed User
with the code

B4X:
Sub ResizeBitmap(bmp As Bitmap, Width As Float, Height As Float) As Bitmap
   Dim img As ImageView
   img.Initialize("")
   img.Width = bmp.Width * Width
   img.Height = bmp.Height * Height
   Dim cvs As Canvas
   cvs.Initialize(img)
   cvs.DrawBitmap(bmp, cvs.TargetRect)
   Dim res As Bitmap = cvs.CreateBitmap
   cvs.Release
   Return res
End Sub

I become the error

B4X:
Application_Start
Error occurred on line: 331 (Main)
Object was not initialized (UIImage)
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Lulaj                -[B4IObjectWrapper object] + 200
  Lulaj                -[B4IImageViewWrapper setBitmap:] + 112
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 292
  Lulaj                +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
  Lulaj                -[B4IShell runMethod:] + 574
  Lulaj                -[B4IShell raiseEventImpl:method:args::] + 1998
Lulaj                -[B4IShellBI raiseEvent:event:params:] + 1442
Lulaj                +[B4IDebug delegate:::] + 52
Lulaj                -[b4i_main _createlistitem:::] + 576
Lulaj                -[b4i_main _setuppage1] + 3936
CoreFoundation       <redacted> + 68
CoreFoundation       <redacted> + 292
Lulaj                +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
Lulaj                -[B4IShell runMethod:] + 574
Lulaj                -[B4IShell raiseEventImpl:method:args::] + 2212
Lulaj                -[B4IShellBI raiseEvent:event:params:] + 1442
Lulaj                __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 1532
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1590
CoreFoundation       CFRunLoopRunSpecific + 516
CoreFoundation       CFRunLoopRunInMode + 108
GraphicsServices     GSEventRunModal + 160
UIKit                UIApplicationMain + 144
Lulaj                main + 108
libdyld.dylib        <redacted> + 2
)
Application_Active

Line 331 is the return
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
I copied the code and got the same issue. Any news on this or is the demo code wrong ?

Thanks !
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Never mind: found out the exception was generated by the fact I was not returning a Bitmap but an ImageView
 
Upvote 0
Top