Safe Bitmap Library

vb1992

Well-Known Member
Licensed User
Longtime User
I wanted to write a small bitmap library
and I am having problems with passing the bitmap
back to the b4a program



B4X:
  public Bitmap loadbitmap(String Directory, String Filename) throws FileNotFoundException   {
    
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inSampleSize = 4;
              Bitmap returnBitmap ;
    
        
              FileInputStream fs = new FileInputStream(Directory + Filename);
       
              //InputStreamWrapper file1 = new  File.InputStreamWrapper();
            
              returnBitmap = BitmapFactory.decodeStream(fs, null, options);   
 
              return returnBitmap;
  
}




 

vb1992

Well-Known Member
Licensed User
Longtime User
Tried this, did not work...




B4X:
  public anywheresoftware.b4a.objects.drawable.BitmapDrawable loadbitmap(String Directory, String Filename) throws FileNotFoundException   {
    
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inSampleSize = 4;
              Bitmap returnBitmap ;
               
              
        
              FileInputStream fs = new FileInputStream(Directory + Filename);
       
              //InputStreamWrapper file1 = new  File.InputStreamWrapper();
            
              returnBitmap = BitmapFactory.decodeStream(fs, null, options);   
               
           anywheresoftware.b4a.objects.drawable.BitmapDrawable bd = new anywheresoftware.b4a.objects.drawable.BitmapDrawable();
            bd.Initialize(returnBitmap);
         
              
              return  bd ;
  
}



Activity.Background=mm
javac 1.6.0_26
src\a\b\c\main.java:211: inconvertible types
found : vb.smart.bitmaps.smartbm
required: android.graphics.drawable.Drawable
mostCurrent._activity.setBackground((android.graphics.drawable.Drawable)(mostCurrent._mm));
^
1 error
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
I wanted to build an extended LoadBitmapSample with memory checking and error trapping and want to catch it and possibly call System.gc() and try again, or display either a smaller image / different image / return a custom error message

I want to extend this to have many options.

But I need to start with the basic library first to get it working above
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim mm As SmartBitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
   mm.loadbitmap(File.DirAssets,"moon.jpg")
   Activity.SetBackgroundImage(mm)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub




Java

B4X:
package vb.smart.bitmaps;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import android.os.Debug;
 
/**
*  
* Load a simple bitmap correctly   
*/
@ActivityObject
@Permissions(values={"android.permission.WRITE_EXTERNAL_STORAGE"})
@ShortName("SmartBitmap")
@Version(1.0f)
 


public class smartbm {
  
  
 
  /**
   * returns a simple bitmap
   */
  
  public Bitmap loadbitmap(String Directory, String Filename) throws FileNotFoundException   {
        
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inSampleSize = 4;
      
      Bitmap returnBitmap;
    
      FileInputStream fs = new FileInputStream(Directory + Filename);
 
      returnBitmap = BitmapFactory.decodeStream(fs, null, options);   
      
      return returnBitmap;

        }

 
}
 
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
thanks, that helped

this is what finally worked

B4X:
File.Copy(File.DirAssets,"moon.jpg",File.DirInternal,"moon.jpg")
       Activity.SetBackgroundImage(mm.loadbitmap(File.DirInternal,"/moon.jpg"))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…