magnify a section of bitmap
I have an image 2816x2112(4:3) that I'm setting as activity background using loadBitmapSample with max width=activity.width(800) and max height=activity.height(1205) with the drawable gravity.center.
I'm wanting to magnify an area of the background by using a small source
rectangle with a destination rectangle of larger size. To do
this magnification I'm using: canvas.drawbitmap(bitmap,source rectangle,destination rectangle)
My issue is that the canvas image is not of the area outlined by the source rectangle(outlined in black by cvs.drawlines), but is instead displaying an area off to the left of the source rectangle.
I'm running on a Nexus 7, and haven't been able to figure this out.
I have an image 2816x2112(4:3) that I'm setting as activity background using loadBitmapSample with max width=activity.width(800) and max height=activity.height(1205) with the drawable gravity.center.
I'm wanting to magnify an area of the background by using a small source
rectangle with a destination rectangle of larger size. To do
this magnification I'm using: canvas.drawbitmap(bitmap,source rectangle,destination rectangle)
My issue is that the canvas image is not of the area outlined by the source rectangle(outlined in black by cvs.drawlines), but is instead displaying an area off to the left of the source rectangle.
I'm running on a Nexus 7, and haven't been able to figure this out.
B4X:
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If File.Exists (File.DirRootExternal, "sp_1149.jpg") = False OR File.Size(File.DirRootExternal, "sp_1149.jpg")=0 Then
File.Copy(File.DirAssets, "sp_1149.jpg", File.DirRootExternal, "sp_1149.jpg")
End If
Activity.LoadLayout("test")
Dim strFile,strDir As String
strFile="sp_1149.jpg"
strDir=File.DirRootExternal
Dim d As BitmapDrawable
d.Initialize(LoadBitmapSample(strDir,strFile,Activity.Width,Activity.Height))
d.Gravity=Gravity.CENTER
Activity.Background=d
Dim cvs As Canvas
cvs.Initialize(Activity)
Dim sRect As Rect
sRect.Initialize(55%x,45%y,60%x,50%y)
Dim dRect As Rect
dRect.Initialize(40%x,60%y,70%x,90%y)
cvs.DrawBitmap(LoadBitmapSample(strDir,strFile,Activity.Width,Activity.Height),sRect,dRect)
cvs.drawline(sRect.left,sRect.Top,sRect.Left,sRect.Bottom,Colors.Black,3dip)
cvs.drawline(sRect.left,sRect.Bottom,sRect.Right,sRect.Bottom,Colors.Black,3dip)
cvs.drawline(sRect.right,sRect.Bottom,sRect.Right,sRect.top,Colors.Black,3dip)
cvs.drawline(sRect.right,sRect.top,sRect.Left,sRect.top,Colors.Black,3dip)
End Sub
Last edited: