Hi all.
I´m trying to add a thumbnail to a picture modified in a canvas. The original picture has a thumbnail 'inside', but the one generated with 'OutPutStream' and the 'WriteToStream' method doesn't have it.
Executing the code attached below you can see the result in the 'Logs' window. You'll need the 'JpegUtils' library.
Is there any way to add or append a thumbnail to a .jpg file generated this way? I know 'LoadBitmapSample', but it creates a new file, and that's not what I'm looking for. I want the thumbnail in the same file as the picture, like in the original picture.
Thanks in advance.
I´m trying to add a thumbnail to a picture modified in a canvas. The original picture has a thumbnail 'inside', but the one generated with 'OutPutStream' and the 'WriteToStream' method doesn't have it.
Executing the code attached below you can see the result in the 'Logs' window. You'll need the 'JpegUtils' library.
Is there any way to add or append a thumbnail to a .jpg file generated this way? I know 'LoadBitmapSample', but it creates a new file, and that's not what I'm looking for. I want the thumbnail in the same file as the picture, like in the original picture.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim exif As ExifData
Dim canvas1 As Canvas
Dim bitmap1, bitmap2 As Bitmap
Dim brect As Rect
Dim iv As ImageView
File.Copy(File.DirAssets, "Sample.jpg", File.DirRootExternal,"Sample.jpg")
bitmap1.Initialize(File.DirRootExternal, "sample.jpg")
bitmap2.InitializeMutable(bitmap1.Width,bitmap1.Height)
canvas1.Initialize2(bitmap2)
brect.Initialize(0,0,bitmap1.Width, bitmap1.Height)
'Add picture to canvas
canvas1.DrawBitmap(bitmap1, Null, brect)
'Add a circle to canvas
canvas1.DrawCircle(100dip, 100dip, 40dip, Colors.Red, False, 10dip)
'Show modified picture
iv.Initialize("iv")
iv.Bitmap=canvas1.Bitmap
iv.Gravity = Gravity.FILL
Activity.AddView(iv,0,0,100%x, 100%y)
'Save picture
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "SampleWithCircle.jpg", False)
canvas1.Bitmap.WriteToStream(Out, 100, "JPEG")
Out.Close
'This code does'n work to add a thumb
Dim thumb As Bitmap = LoadBitmapSample(File.DirRootExternal, "SampleWithCircle.jpg", 100dip, 100dip)
' Dim Out2 As OutputStream
' Out2 = File.OpenOutput(File.DirRootExternal, "SampleWithCircle.jpg", True)
' thumb.WriteToStream(Out2,100,"JPEG")
' Out2.Close
'Test if "Sample.jpg" has thumbnail
exif.Initialize(File.DirRootExternal, "Sample.jpg")
Log("Sample has thumbnail: " & exif.hasThumbnail)
'Test if "SampleWithCircle.jpg" has thumbnail
exif.Initialize(File.DirRootExternal, "SampleWithCircle.jpg")
Log("SampleWithCircle has thumbnail: " & exif.hasThumbnail)
End Sub
Thanks in advance.