Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphics 黑莓-如何调整图像大小?_Graphics_Blackberry_Drawing_Custom Controls_Image Scaling - Fatal编程技术网

Graphics 黑莓-如何调整图像大小?

Graphics 黑莓-如何调整图像大小?,graphics,blackberry,drawing,custom-controls,image-scaling,Graphics,Blackberry,Drawing,Custom Controls,Image Scaling,我想知道我们是否可以调整图像的大小。假设我们想在黑莓手机屏幕上绘制一幅实际大小为200x200、大小为100x100的图像 谢谢我不是黑莓程序员,但我相信其中的一些链接将帮助您: 只是一种选择: 请记住,黑莓默认的图像缩放功能非常原始,通常看起来不太好。如果您正在构建5.0版,则可以使用双线性或Lanczos等过滤器来更好地缩放图像。使用该方法可以非常简单地完成此操作。您需要为它提供缩放宽度和高度的因子(作为一个整体) 下面是一些示例代码,它通过使用RIM的类将原始图像大小除以所需大小来确

我想知道我们是否可以调整图像的大小。假设我们想在黑莓手机屏幕上绘制一幅实际大小为200x200、大小为100x100的图像


谢谢

我不是黑莓程序员,但我相信其中的一些链接将帮助您:



只是一种选择:


请记住,黑莓默认的图像缩放功能非常原始,通常看起来不太好。如果您正在构建5.0版,则可以使用双线性或Lanczos等过滤器来更好地缩放图像。

使用该方法可以非常简单地完成此操作。您需要为它提供缩放宽度和高度的因子(作为一个整体)

下面是一些示例代码,它通过使用RIM的类将原始图像大小除以所需大小来确定宽度和高度的比例因子

如果你足够幸运,能够成为OS5.0的开发者,Marc发布了一个到的链接,这个链接比我上面描述的更清晰、更通用。例如:

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;
}

(当然,您可以根据需要替换过滤器/缩放选项。)

对于BlackBerry JDE 5.0或更高版本,您可以使用API。

这里是函数,或者您可以说调整图像大小的方法,可以根据需要使用它:

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();

我为黑莓应用程序开发的新手发布这个答案。下面的代码用于处理URL中的位图图像,并在不影响纵横比的情况下调整其大小:

   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;
}
方法resizeImage在方法imageFromServer(字符串url)内调用。 1) 使用EncodedImage img处理来自服务器的图像。 2) 位图bitmp=resizeImage(img.getBitmap(),100100);
参数传递给resizeImage(),resizeImage()的返回值设置为位图bitmp

@TreeUK:我现在在工作代码中有这个确切的功能。您是否将
int
s转换为
Fixed32
,并使用
Fixed32.div()
计算比例因子?普通的整数除法不会把它切掉。谢谢,我用错了。与整数无关,但仍然错误。只需调用此方法并将其保存到位图中即可。.enjoyscaleInto()位图自OS 5.0开始提供。@Lucas是的,自BlackBerry API 5.0.0开始提供
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;
}
   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;
}