Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 4 Jahren, 10 Monaten
Letzter Beitrag:
vor 2 Jahren, 4 Monaten
Beteiligte Autoren:
Danny Lauwers, Fabrice Harari, CCC2, Arie, evanpan

[WM17] Andriod Resize Image ?

Startbeitrag von Danny Lauwers am 10.04.2013 15:39

Hi,

What I want to accomplish:
1. Take a picture with the android camera
2. Resize it without distorting the image (Homothetic)
3. Upload via a Webservice to my ERP system

Where is the problem, in 2 resizing it !!

When the image of the camera is taken with VideoStartApp(viPictureCapture) the picture is stored in a JPG file. I assign the Image control to the path to load the image into the control and show it on the Andriod Phone. Looks good, works great !

Then I need to resize the image en compress it.
I tried

dResize(IMG_Foto,640,480)
bufImageBuffer = dSaveImageJPG(IMG_Temp,inMemory,50)
sBase64String = Crypt(bufImageBuffer,"",cryptNone,True)

Once I have a Base64String I can upload it without problems.

The result I get is a picture with black borders around it
[attachment 302 test.jpg]

If you save the image of a Image control, it seems to save the total control and not only the image itself.

I tried the same with Windev 17, and there I have used the Image variable and that works OK.

I also tried to use a second Image control of the same size what I want to resize, but this has a double black border around it ??

Anybody an idea on how to correct size an image taken from the android camera ?

Thanks
Danny

Antworten:

Hi Danny

I haven't tried in Android, but both in windev and webdev, I have been resizing images for years now with the following methods, and I suppose it will work in mobile the same way...

It is based on the fact that as you could see dsaveimage is saving the image as the image field is...

So: Load your image in a high quality image field, then resize the FIELD (not the image, not with dresize) by changing it's ..width ..height properties...

Then do a dsaveImage and your base64/transmission.

That should do it

Best regards

von Fabrice Harari - am 10.04.2013 15:47
10 times faster

sPhoto is string = VideoStartApp(viPictureCapture)
sDest is string
VideoGenerateThumbnail(sPhoto,sDest,600,480)

or the one I use
VideoGenerateThumbnail(sPhoto,sDest)

if you need it to be more sophisticated you have to switch to Java.
There a examples on the internet.
Once you get a bit familiair with Java it opens a new world for "stuff not suppoerted yet".

von Arie - am 10.04.2013 16:09
Hi,

Thanks for the tips, I have solved it this way (see code below).

Another issue is that on different Mobile Phones (Android) sometimes the image orientation is correct, sometimes its not.

I would use EXIF to get the orientation in order to extra rotate the image, but this is currently not supported on Android. Any Idea's ?

The following code is my (being a newbie) way of resizing images on Android !



//
// The Temp Image control must be set to HQ - Homothetic, and can be offscreen
// In Windev we could use "Image" variable and dloadimage, dresize, etc... to resize the image
// For Windev Mobile, we can use this function that uses a Image Control to do the risizing
// If you don't need to recompress your JPEG, you can use VideoGenerateThumbnail(sPhoto,sDest,600,480)
//

PROCEDURE ResizeImageFile(LOCAL fsource is string, LOCAL fdest is string, TmpImageControl, LOCAL NewSize, LOCAL JPEGQuality, SaveAsFile = True, ImageBuffer is Buffer = Null)
ImageInfo is string
nPich is int
nPicw is int
nNEwPich is int
nNewPicw is int

// Reset Image Control
TmpImageControl..ImageHeight = -1
TmpImageControl..ImageWidth = -1

// Get the Width and Heigth of the image
ImageInfo = BitmapInfo(fsource)
nPich = Val(ExtractString(ImageInfo, 3))
nPicw = Val(ExtractString(ImageInfo, 2))

// Is this Portrait or Landscape
// Resize the largest side always to the NewSize
IF(nPich > nPicw) THEN
// Portrait
nNEwPich = NewSize
nNewPicw = nPicw / (nPich / NewSize)
ELSE
// Landscape
nNewPicw = NewSize
nNEwPich = nPich / (nPicw / NewSize)
END

// Load the Image
TmpImageControl = fsource

// Set the Size of the Image control
TmpImageControl..Width = nNewPicw
TmpImageControl..Height = nNEwPich

IF(SaveAsFile) THEN
// Save the resized image as JPG with compressionlevel
dSaveImageJPEG(TmpImageControl,fdest,JPEGQuality)
ELSE
// Save the file in memory
ImageBuffer = dSaveImageJPEG(TmpImageControl,inMemory,JPEGQuality)
END

// Reset size of Image Control
TmpImageControl = ""
TmpImageControl..Width = 50
TmpImageControl..Height = 50



Thanks
Danny

von Danny Lauwers - am 11.04.2013 11:56
Hi Dannyu

EXIF information is jus tags that are added at then end of the image fil, if I remember correctly.

So even if exif info reading is not supported in your version of android, reading the file and extracting the info by code shouldn't be too hard, as exif information format is available with a simple google search

At least, that's what I would try to do

von Fabrice Harari - am 11.04.2013 14:28
Hi,

I created a JAVA function in WM17 that gets the orientation


//
// Check to see if the image must be rotated or not
//PROCEDURE CheckRotation(sSource is string)
//
import java.io.IOException;
import android.media.ExifInterface;

public static String CheckOrientationJava(String fSource)
{
String Orientation = "-2";

try {
ExifInterface ExifData = new ExifInterface(fSource);

Orientation = ExifData.getAttribute(ExifInterface.TAG_ORIENTATION);
} catch(IOException e) {
return "-1";
}

return Orientation;
}


von Danny Lauwers - am 15.04.2013 07:08
Hi,
I wonder do I need another
image resizing control to help me deal with those codes?

// Load the Image
TmpImageControl = fsource

// Set the Size of the Image control
TmpImageControl..Width = nNewPicw
TmpImageControl..Height = nNEwPich

IF(SaveAsFile) THEN
// Save the resized image as JPG with compressionlevel
dSaveImageJPEG(TmpImageControl,fdest,JPEGQuality)
ELSE
// Save the file in memory
ImageBuffer = dSaveImageJPEG(TmpImageControl,inMemory,JPEGQuality)
END

// Reset size of Image Control
TmpImageControl = ""
TmpImageControl..Width = 50
TmpImageControl..Height = 50

Any suggetsion will be appreciated. Thanks in advance.



Best regards,
Pan


von evanpan - am 17.10.2015 07:24
Hi Danny,

Please read the last post in this topic

http://27130.foren.mysnip.de/read.php?27131,547368,547495#msg-547495

von CCC2 - am 17.10.2015 15:09
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.