Here is the JavaObject V2.01 files. Try them and see what happens
Yes.
Look at chapter 14.7.2 Additional libraries folder in the Beginner's Guide.
Here is the JavaObject V2.01 files. Try them and see what happens
Sub Activity_Create(FirstTime As Boolean)
p2.Initialize("")
p2.AddView(imgTest, 5dip, 2dip, 100dip, 100dip)
clv1.Add(p2, 160dip, "Test")
Dim bm, bm2 As Bitmap
Dim imgTest As ImageView
bm.Initialize(File.DirRootExternal, "test.jpg")
bm2 = nativeMe.RunMethod("getBubbleBitmap",Array(bm))
imgTest.Bitmap = bm2
end sub
See attached and comments that I have added in the code. I think it has something to do with the (small) size of your jpg file. Have changed the call to getBubbleBitmap:anybody ?
Dim tw As Int = 400 'play around with this value - it was hardcoded as 1000 in method getBubbleBitmap
Dim th As Int = 400 'play around with this value - it was hardcoded as 1000 in method getBubbleBitmap
bm.Initialize(File.DirAssets, "a.jpg")
bm2 = nativeMe.RunMethod("getBubbleBitmap",Array(bm, tw, th))
public static Bitmap getBubbleBitmap(Bitmap scaleBitmapImage, int targetWidth, int targetHeight) {
// int targetWidth = 400;
// int targetHeight = 400;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.moveTo((float) targetWidth/2, (float) 0.0);
path.lineTo(targetWidth, (float) 0.0);
path.lineTo((float)targetWidth, targetHeight/2);
RectF oval = new RectF();
oval.set(0, 0, targetWidth, targetHeight);
path.addArc(oval, 0, 270);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
targetHeight), null);
return targetBitmap;
}
Just one thing, Why does the image have different size with different device ?, I'm using the same value here:
Dim tw As Int = 180
Dim th As Int = 180
it didn't work with dipTry to use DIP..
Dim tw As Int = 180dip
...
No, have not. Have not looked at the code in a long time (i.e is it in a B4A class or not). If not in a B4A class then the inline java code can easily be moved to a B4A class and compiled to a B4A library. If already in a B4A class then it just needs to be compiled to a library (i.e from B4A - nothing special required). Will check a bit later - busy with video recorder Front / Back option.Hi, you havent converted this into a library by any chance?
No, have not. Have not looked at the code in a long time (i.e is it in a B4A class or not). If not in a B4A class then the inline java code can easily be moved to a B4A class and compiled to a B4A library. If already in a B4A class then it just needs to be compiled to a library (i.e from B4A - nothing special required). Will check a bit later - busy with video recorder Front / Back option.
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
public Bitmap getHexagonShape(Bitmap scaleBitmapImage) {
int targetWidth = 200;
int targetHeight =200;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
float stdW = 200;
float stdH = 200;
float w3 =stdW / 2;
float h2 = stdH / 2;
float radius=stdH/2-10;
float triangleHeight = (float) (Math.sqrt(3) * radius / 2);
float centerX = stdW/2;
float centerY = stdH/2;
path.moveTo(centerX, centerY + radius);
path.lineTo(centerX - triangleHeight, centerY + radius/2);
path.lineTo(centerX - triangleHeight, centerY - radius/2);
path.lineTo(centerX, centerY - radius);
path.lineTo(centerX + triangleHeight, centerY - radius/2);
path.lineTo(centerX + triangleHeight, centerY + radius/2);
path.moveTo(centerX, centerY + radius);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth,
targetHeight), null);
return targetBitmap;
}
Hi everyone, I created a different hexagon shape from the inline Java provided in the first examples... Here's the code for my shape:
B4X:import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public Bitmap getHexagonShape(Bitmap scaleBitmapImage) { int targetWidth = 200; int targetHeight =200; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); float stdW = 200; float stdH = 200; float w3 =stdW / 2; float h2 = stdH / 2; float radius=stdH/2-10; float triangleHeight = (float) (Math.sqrt(3) * radius / 2); float centerX = stdW/2; float centerY = stdH/2; path.moveTo(centerX, centerY + radius); path.lineTo(centerX - triangleHeight, centerY + radius/2); path.lineTo(centerX - triangleHeight, centerY - radius/2); path.lineTo(centerX, centerY - radius); path.lineTo(centerX + triangleHeight, centerY - radius/2); path.lineTo(centerX + triangleHeight, centerY + radius/2); path.moveTo(centerX, centerY + radius); canvas.clipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
This works very well, however I would like to know how to achieve a border around the image. Anyone got an idea how to go about this?
Ikr, just don't know exactly how to do it... the code I posted is borrowed.You will have to add code to the inline Java code to draw it.
Browse the web and see if you can find something on the Stackoverflow forum. Just type in "bitmap draw border bitmap stackoverflow" in you search engine and the learn from the links that pop up from the search.Ikr, just don't know exactly how to do it... the code I posted is borrowed.
guess we think slightly alike... I did that earlier and after several readings, made this to modification to my code...Browse the web and see if you can find something on the Stackoverflow forum
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Color;
public Bitmap getHexagonShape(Bitmap scaleBitmapImage) {
Paint mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.FILL);
int targetWidth = 200;
int targetHeight = 200;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
float stdW = 200;
float stdH = 200;
float w3 =stdW / 2;
float h2 = stdH / 2;
float radius=stdH/2-10;
float triangleHeight = (float) (Math.sqrt(3) * radius / 2);
float centerX = stdW/2;
float centerY = stdH/2;
path.moveTo(centerX, centerY + radius);
path.lineTo(centerX - triangleHeight, centerY + radius/2);
path.lineTo(centerX - triangleHeight, centerY - radius/2);
path.lineTo(centerX, centerY - radius);
path.lineTo(centerX + triangleHeight, centerY - radius/2);
path.lineTo(centerX + triangleHeight, centerY + radius/2);
path.moveTo(centerX, centerY + radius);
//I made changes here
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth((float)5);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth,
targetHeight), mPaint); //Added the Paint here
return targetBitmap;
}
Take a look here - maybe it puts you on the right trackguess we think slightly alike... I did that earlier and after several readings, made this to modification to my code...
B4X:import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.Color; public Bitmap getHexagonShape(Bitmap scaleBitmapImage) { Paint mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.FILL); int targetWidth = 200; int targetHeight = 200; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); float stdW = 200; float stdH = 200; float w3 =stdW / 2; float h2 = stdH / 2; float radius=stdH/2-10; float triangleHeight = (float) (Math.sqrt(3) * radius / 2); float centerX = stdW/2; float centerY = stdH/2; path.moveTo(centerX, centerY + radius); path.lineTo(centerX - triangleHeight, centerY + radius/2); path.lineTo(centerX - triangleHeight, centerY - radius/2); path.lineTo(centerX, centerY - radius); path.lineTo(centerX + triangleHeight, centerY - radius/2); path.lineTo(centerX + triangleHeight, centerY + radius/2); path.moveTo(centerX, centerY + radius); //I made changes here mPaint.setColor(Color.WHITE); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth((float)5); canvas.clipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), mPaint); //Added the Paint here return targetBitmap; }
Still shows no border
thanks a lot, I'm on it... will revert if anything happens.Take a look here