Android Question hudge narrow picture - loading partially

peacemaker

Expert
Licensed User
Longtime User
HI, All

If some data is a loooong narrow picture (format can be chosen) that for sure will give OutOfMemory error - how to load it part by part for scrolling left-to-right horizontally ?
What picture format better to choose?

How to use BitmapRegionDecoder ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
I'm trying Inline Java, but .... failed...

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim NativeMe As JavaObject
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    NativeMe.InitializeContext
    File.Copy(File.DirAssets, "1.jpg", File.DirInternal, "1.jpg")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Dim fn As String = File.Combine(File.DirInternal, "1.jpg")
    Dim lstBMPinfo As Int = NativeMe.RunMethod("getBMPinfo", Array(fn))
    Log(lstBMPinfo)
    Dim area As Rect
    area.Initialize(5, 5, 10, 10)
    Dim bmp As Bitmap = NativeMe.RunMethod("getRegionBitmap", Array(fn, area))
End Sub

#if Java
import java.util.*;
import java.lang.*;
import java.io.File;
import android.graphics.*;

public List getBMPinfo(String path) {
    //String path = dir + File.separatorChar + fn;
    BA.Log(path);
    BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder
                .newInstance(path, false);
      
        // Get the width and height of the full image
        int fullWidth = bitmapRegionDecoder.getWidth();
        int fullHeight = bitmapRegionDecoder.getHeight();
      
        List lst = new ArrayList();
        lst.add(fullWidth);
        lst.add(fullHeight);
        return lst;  
}
public Bitmap getRegionBitmap(String path, Rect area) {
    Bitmap regionBitmap = null;
    BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder
                .newInstance(path, false);
    Rect regionRect = new Rect(area.left, area.top, area.right, area.bottom);
    regionBitmap = bitmapRegionDecoder.decodeRegion(regionRect, null);
    return regionBitmap;
}
#end if

Help anyone, who knows Java...
 

Attachments

  • sample_code.zip
    312.7 KB · Views: 140
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Sorry, Erel, it's unclear.
What about BitmapRegionDecoder imlementation ? I guess, it's useful for whole comunity ?
 
Upvote 0
Top