Resizing a image

aloof

Member
Licensed User
Longtime User
Hi

I'm looking at making a app to resize images.... ive looked at some samples of bitmap.
i think it is a little advanced for me i dont understand the steps involved... if someone can explain it... ie load file, create new file, define size or whatever it may be

thanks
 
1. Loading a Bitmap:

Code:
Dim bmp As Bitmap
bmp.Initialize(myDirectory, myFile)

2. Scaling a Bitmap (Reflection Library needed):

Code:
Sub CreateScaledBitmap(Original As Bitmap, NewWidth As Int, NewHeight As Int) As Bitmap
    Dim r As Reflector
    Dim b As Bitmap
   
   
    b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
        Array As Object(Original, NewWidth, NewHeight, true), _
        Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
    Return b
End Sub

3. Saving a bitmap:

Code:
Sub SaveBitmap (bmp As Bitmap, MyDir As String, MyFile As String)
   Dim out As OutputStream
   out=File.OpenOutput(MyDir,MyFile, False)
   bmp.WriteToStream(out,100,"PNG")
   out.close
End Sub
 
Last edited:
Upvote 0
i tried using most of your code but couldnt get it working... can you see something i dont? thanks

Sub CreateScaledBitmap(bmp As Bitmap, NewWidth As Int, NewHeight As Int) As Bitmap
Dim r As Reflector
Dim b As Bitmap


b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(bmp, NewWidth, NewHeight, True), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub

Sub SaveBitmap (bmp As Bitmap, dir As String, filename As String)
Dim out As OutputStream
out=File.OpenOutput(File.DirRootExternal, "reduced/" & "-Lower2.jpeg", False)
bmp.WriteToStream(out,5,"JPEG")
out.close
End Sub

Sub buttongo_click
Dim dir As String
Dim filename As String
Dim original As Bitmap
Dim bmp As Bitmap
bmp.Initialize(File.DirRootExternal, "reduced/" & "-Lower.jpeg")

CreateScaledBitmap(bmp,300,400)
SaveBitmap(bmp,File.DirRootExternal, "reduced/" & "-Lower.jpeg")

End Sub
 
Upvote 0
Code:
"reduced/" & "-Lower.jpeg"

i suppose, this is not a valid filename.
 
Upvote 0
this line in your code:

Code:
CreateScaledBitmap(bmp,300,400)

should be

Code:
bmp = CreateScaledBitmap(bmp,300,400)
 
Upvote 0
Hello,

I noticed:

Code:
bmp.WriteToStream(out,5,"JPEG")

also that line of code is really low resolution
I think using 80 gives you decent resolution and low files size

bmp.WriteToStream(out,80,"JPEG")

Best...
 
Last edited:
Upvote 0
Hi Djembefola,

Sorry, I haven't checked the Java classes, but would it be possible to apply this:

Code:
Sub CreateScaledBitmap(Original As Bitmap, NewWidth As Int, NewHeight As Int) As Bitmap
    Dim r As Reflector
    Dim b As Bitmap
    b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
        Array As Object(Original, NewWidth, NewHeight, true), _
        Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
    Return b
End Sub

modified for inverting and/or gray-scaling images?
Using agraham's reflector this seems to be a formidable approach to
image processing without requiring lots of code.
 
Upvote 0
Hi Djembefola,

Sorry, I haven't checked the Java classes, but would it be possible to apply this...modified for inverting and/or gray-scaling images?
Using agraham's reflector this seems to be a formidable approach to
image processing without requiring lots of code.

Hi Alfcen,
I know nothing about image processing, but i suppose, in most cases there are several objects/methods involved in applying image effects. The reflection library is fine, as long as you need just a single function call.
 
Upvote 0
Thanks for you time. I will dig deeper into available objects and methods.
Cheers
Robert
 
Upvote 0
Resize and rotate images using handles

Hi,

How can I let users rotate and re-size loaded images on screen using handles around images corners?

attachment.php


Something like the times when you work with images in image editing software that let you resize and rotate images by mouse.

Thanks.
 

Attachments

  • handles.jpg
    handles.jpg
    47.3 KB · Views: 1,567
Upvote 0
Back
Top