Android Question How to handle large bitmaps?

Discussion in 'Android Questions' started by welu1805, Feb 3, 2015.

  1. welu1805

    welu1805 Active Member Licensed User

    Hi all,

    I scanned 5 musical note sheets under win 7 and generated a "vertical panorama picture" with IrvanView. The file properties are: width=1000, height=7000 dpi.

    With a prog under Delphi 5 and Win 7 I can load this bitmap and scroll it. No problems with memory, no exceptions.

    Now I tried to do the same with b4a. I load the bitmap with:

    bm.Initialize(folder, "MyNotes")

    No memory error. bm.Width shows 1000, bm.height shows 7000.

    Then I put the bitmap "bm" to a imageView.bitmap:

    img1.Bitmap = bm

    No exception, no error.

    The img1 is on a panel of a scrollview, because I want to scroll the "very long" picture, but I see nothing: The screen is empty, no error, no exception.

    Has anyone an idea what I can do to show and scroll this large bitmap?
  2. klaus

    klaus Expert Licensed User

    Without seeing your code it's very difficult to give you a concrete advice.
    You don't need to put the image on an ImageView, you can put it directly on the ScrollView.Panel.
    Peter Simpson likes this.
  3. welu1805

    welu1805 Active Member Licensed User

    Soory Klaus, I am new to B4A and I don't now how to put it directly on the ScrollView.Panel.

    ScrollView.Panel has no property "bitmap" or "image"? Can you help me?
  4. lemonisdead

    lemonisdead Well-Known Member Licensed User

    ScrollView has a .background and a .SetBackgroundImage properties or you can add a panel to the Scrollview. On that panel you can put your ImageView
  5. Informatix

    Informatix Expert Licensed User

    Android is not Windows and Java is not Delphi. Android devices have a limited memory. Low-end devices have only 512 MB of RAM and this size was even lower (128 MB) a few years ago. As apps are supposed to stay in memory while you switch to another app, there's a limitation to avoid allocating all memory to a single application. So the Java memory heap is limited to a fraction of the total available memory. This heap memory size depends on the device. It can be 32 MB here, 128 MB there. Historically, it was as low as 16 MB. Subtract a few MB to this size for the code of your app and you'll see that you don't have a lot of room for big images. An image 1000x7000 takes 26.7 MB.
  6. welu1805

    welu1805 Active Member Licensed User

    Thank you all for your response.

    Now I know it is not possible to load the entire bitmap file. I think it would be better to generate one file for each note sheet. In my app I should have two button "Next" and "Previous" to load the other sheets.

    Is there a possibility to show the user what is the maximum of bitmap file to laod (width anf height)?
  7. welu1805

    welu1805 Active Member Licensed User

    My idea is to provent the user form loading a image file that is to large.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice