Blackberry - jak zmienić rozmiar obrazu?

Chciałem wiedzieć, czy możemy zmienić rozmiar obrazu. Załóżmy, że chcemy narysować obraz o wymiarach rzeczywistych 200x200 z rozmiarem 100 x 100 na naszym ekranie blackberry.

Thanks

Author: Juha Syrjälä, 2009-11-20

8 answers

 7
Author: Maksym Gontar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:11:20

Można to zrobić całkiem po prostu za pomocą EncodedImage.scaleImage32() metoda. Musisz podać czynniki, według których chcesz skalować szerokość i wysokość (jako Fixed32).

Oto przykładowy kod, który określa współczynnik skali dla szerokości i wysokości, dzieląc oryginalny rozmiar obrazu przez żądany rozmiar, używając RIM ' s Fixed32 klasy.

public static EncodedImage resizeImage(EncodedImage image, int newWidth, int newHeight) {
    int scaleFactorX = Fixed32.div(Fixed32.toFP(image.getWidth()), Fixed32.toFP(newWidth));
    int scaleFactorY = Fixed32.div(Fixed32.toFP(image.getHeight()), Fixed32.toFP(newHeight));
    return image.scaleImage32(scaleFactorX, scaleFactorY);
}
Jeśli masz szczęście być programistą OS 5.0, Marc zamieścił link do nowych API , które są dużo jaśniejszy i bardziej wszechstronny niż ten, który opisałem powyżej. Na przykład:
public static Bitmap resizeImage(Bitmap originalImage, int newWidth, int newHeight) {
    Bitmap newImage = new Bitmap(newWidth, newHeight);
    originalImage.scaleInto(newImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
    return newImage;
}

(oczywiście możesz zastąpić opcje filtrowania/skalowania w zależności od potrzeb.)

 10
Author: Skrud,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-15 18:21:16

Nie jestem programistą Blackberry, ale wierzę, że niektóre z tych linków Ci pomogą:

Artykuł o zmianie rozmiaru obrazu
Zmiana rozmiaru bitmapy na Blackberry
pytanie o skalowanie obrazu Blackberry

 3
Author: luvieere,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-20 11:09:27

Należy pamiętać, że domyślne skalowanie obrazu wykonane przez BlackBerry jest dość prymitywne i ogólnie nie wygląda zbyt dobrze. Jeśli budujesz dla wersji 5.0, istnieje nowe API do znacznie lepszego skalowania obrazu za pomocą filtrów takich jak bilinear lub Lanczos.

 3
Author: Marc Novakowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-11-20 17:04:11

Dla BlackBerry JDE 5.0 lub nowszych, można użyć API scaleInto .

 2
Author: Hermes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-14 12:49:21
in this there is two bitmap.temp is holding the old bitmap.In this method you just pass
bitmap ,width,height.it return new bitmap of your choice.

  Bitmap ImgResizer(Bitmap bitmap , int width , int height){
    Bitmap temp=new Bitmap(width,height);
    Bitmap resized_Bitmap = bitmap;
    temp.createAlpha(Bitmap.HOURGLASS);
    resized_Bitmap.scaleInto(temp , Bitmap.FILTER_LANCZOS);
    return temp;
}
 1
Author: iKushal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-20 11:08:15

Oto funkcja lub możesz powiedzieć metoda zmiany rozmiaru obrazu, użyj go jak chcesz:

int olddWidth;
int olddHeight;
int dispplayWidth;
int dispplayHeight;

EncodedImage ei2 = EncodedImage.getEncodedImageResource("add2.png");
olddWidth = ei2.getWidth();
olddHeight = ei2.getHeight();
dispplayWidth = 40;\\here pass the width u want in pixels
dispplayHeight = 80;\\here pass the height u want in pixels again

int numeerator = net.rim.device.api.math.Fixed32.toFP(olddWidth);
int denoominator = net.rim.device.api.math.Fixed32.toFP(dispplayWidth);
int widtthScale = net.rim.device.api.math.Fixed32.div(numeerator, denoominator);
numeerator = net.rim.device.api.math.Fixed32.toFP(olddHeight);
denoominator = net.rim.device.api.math.Fixed32.toFP(dispplayHeight);
int heighhtScale = net.rim.device.api.math.Fixed32.div(numeerator, denoominator);
EncodedImage newEi2 = ei2.scaleImage32(widtthScale, heighhtScale); 
Bitmap _add =newEi2.getBitmap();
 0
Author: Himanshu Sharma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-12-07 09:11:13

Zamieszczam odpowiedzi dla początkujących w rozwoju aplikacji Blackberry. Poniższy kod służy do przetwarzania obrazów bitmapowych z adresu URL i zmiany ich rozmiaru bez obciążania proporcjami:

   public static Bitmap imageFromServer(String url)
{
Bitmap bitmp = null;
try{
HttpConnection fcon = (HttpConnection)Connector.open(url);
int rc = fcon.getResponseCode();
if(rc!=HttpConnection.HTTP_OK)
{
    throw new IOException("Http Response Code : " + rc);            
}
InputStream httpInput = fcon.openDataInputStream();
InputStream inp = httpInput;
byte[] b = IOUtilities.streamToBytes(inp);
EncodedImage img = EncodedImage.createEncodedImage(b, 0, b.length);
bitmp = resizeImage(img.getBitmap(), 100, 100);
}
catch(Exception e)
{
Dialog.alert("Exception : " + e.getMessage());          
}
return bitmp;
}

public static Bitmap resizeImage(Bitmap originalImg, int newWidth, int newHeight)
{
    Bitmap scaledImage = new Bitmap(newWidth, newHeight);
    originalImg.scaleInto(scaledImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);
    return scaledImage;
}

Metoda resizeImage jest wywołana wewnątrz metody imageFromServer (String url). 1) obraz z serwera jest przetwarzany za pomocą EncodedImage img. 2) Bitmap bitmp = resizeImage (img.getBitmap (), 100, 100); parametry są przekazywane do resizeImage (), a wartość zwracana z resizeImage () jest ustawiona na bitmapę bitmp.

 0
Author: Alvin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-06 14:56:24