iOS Question Crop image area from a zoomed pic

joilts

Member
Licensed User
Longtime User
Hi to all, I got a Camera Example integrated with Image Zoom lib. I really don´t remember the author to put the proper credits here.

I've made some changes and I was able to zoom image, but I don´t know how to use canvas well. At B4A version, I got an example that worked fine (used canvas to get the desired area), but with B4i I can´t find. Can anyone give me a help? Attached is my source code.

Thanks in advance,
Jorge
 

Attachments

  • zoomCrop.zip
    10.7 KB · Views: 356
Last edited:

joilts

Member
Licensed User
Longtime User
Did you tried imgZoom.ZoomedImage ?
Thanks for reply.
Yes, I tried this. I got the Zoomed image, the problem is that after use "canvas.drawBitmap" I get the same image (full size) not the rectangle area.

B4X:
Sub btAssociar_Click
    Dim cvs As Canvas

    cvs.initialize(Panel1)
   
    Dim SrcRect As Rect
    SrcRect.Initialize( Panel2.Left , Panel2.Top , Panel2.Left + Panel2.Width ,Panel2.Top + Panel2.Height)

    Dim DestRect As Rect
    DestRect.Initialize(0%x,0%y,Main.imageToCrop.Width, Main.imageToCrop.Height)
   
    Dim Bitmap1 As Bitmap
    Bitmap1 = cvs.CreateBitmap
    ImageView1.Bitmap = Bitmap1
    ImageView1.BringToFront
    ImageView1.Visible = True
   
    DrawBitmap(cvs, Bitmap1,SrcRect,DestRect)
   
    ImageView1.Bitmap = cvs.CreateBitmap
    ImageView1.BringToFront
    ImageView1.Visible = True
   
End Sub
 
Upvote 0

joilts

Member
Licensed User
Longtime User
Sincerly I dont understand.

ImgZoom.ZoomedImage return a new bitmap with the zoomed part. try to save the imgZoom.ZoomedImage to camera roll and you will see.

Image Zoom is working fine. It returns only the zoomed part. My problem is that I want to get only a small part from the zoomed image part. The small rectangle with white border as show in the following video (as it was too big, added the link to youtube - ).

In this video example the cropped image would have only the "H", but I get the zoomed part.
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
Upvote 0

joilts

Member
Licensed User
Longtime User
did you found the Sub ?
Yes I found, thanks for help. Tried two different approachs: created a ImageInRect2(img As Bitmap,left As Float, top As Float, width As Float, height As Float) As Bitmap to use to crop a bitmap image and also create a ZoomedImageArea(l As Float, t As Float ,w As Float,h As Float) As Bitmap that converts left, top, width and height using scale, like in ZoomedImage sub.
Unfortunately I was unable to get the desired area in both cases.
I changed project to show a panel and an image view with them zoomed image (returned by original method) and then the zoomed image area I created. They are showed rotated, probably I´m doing something wrong. This is the new project. Going to try to understand what is happening. Thanks for all help and time spent til now.
 

Attachments

  • zoomCrop1.1.zip
    10.9 KB · Views: 304
Last edited:
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
try this

1. Add imgZoom to Panel1 (not Page)

2.

B4X:
Dim sc As Int=GetDeviceLayoutValues.NonnormalizedScale
    Dim Bitmap1 As Bitmap
    Bitmap1 = cvs.CreateBitmap
    Bitmap1=imgZoom.ImageInRect2(Bitmap1,SrcRect.Left*sc,SrcRect.Top*sc,SrcRect.Width*sc,SrcRect.Height*sc)

ImageView.Bitmap=Bitmap1
 
Upvote 0

joilts

Member
Licensed User
Longtime User
Thanks to Narek Adonts, it worked perfect, exactly as desired.
Here is the final example project as reference if anyone needs something similar.
If you like, please like Narek at the previous post. He did all job.

Thanks again Narek, have a nice weekend.
 

Attachments

  • zoomCrop1.2.zip
    11.1 KB · Views: 362
Upvote 0

joilts

Member
Licensed User
Longtime User
Thanks to Narek Adonts, it worked perfect, exactly as desired.
Hi Again. My app is working fine at iPhone 4 and iPhone 5, but when I get to iPad 2, the zoom action is not working. Can you help me?
As it was difficult to explain, here is another video:


Thanks Again
 
Upvote 0

joilts

Member
Licensed User
Longtime User
Thanks again Narek. Sorry for take so long to answer (holiday). I've tried MaxScale before, but did it in wrong way. After using it right, work.
 
Upvote 0
Top