如何調整來自HTTP服務器的圖像的大小和黑莓屏幕的寬度?請任何解決方案。如何根據黑莓的高度和寬度調整圖像大小
1
A
回答
1
從圖像的字節創建一個EncodedImage。
使用Display.getHeight()
和Display.getWidth()
來獲得顯示器的尺寸。
然後使用EncodedImage.scaleImage32()
進行調整大小。請確認this post。
2
嘗試使用參數Disply.getWidth()& Display.getHieght()。
package CustomizedField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
public class GPATools
{
/**
* Resizes a bitmap with an alpha channel (transparency)
* without the artifacts introduced
* by <code>scaleInto()</code>.
*
* @param bmpSrc Source Bitmap
* @param nWidth New Width
* @param nHeight New Height
* @param nFilterType Filter quality to use. Can be
* <code>Bitmap.FILTER_LANCZOS</code>,
* <code>Bitmap.FILTER_BILINEAR</code> or
* <code>Bitmap.FILTER_BOX</code>.
* @param nAspectRatio Specifies how the picture is resized. Can be
* <code>Bitmap.SCALE_TO_FIT</code>,
* <code>Bitmap.SCALE_TO_FILL</code> or
* <code>Bitmap.SCALE_STRETCH</code>.
* @return The resized Bitmap in a new object.
*/
public static Bitmap ResizeTransparentBitmap(Bitmap bmpSrc,
int nWidth, int nHeight, int nFilterType, int nAspectRatio)
{
if(bmpSrc== null)
return null;
//Get the original dimensions of the bitmap
int nOriginWidth = bmpSrc.getWidth();
int nOriginHeight = bmpSrc.getHeight();
if(nWidth == nOriginWidth && nHeight == nOriginHeight)
return bmpSrc;
//Prepare a drawing bitmap and graphic object
Bitmap bmpOrigin = new Bitmap(nOriginWidth, nOriginHeight);
Graphics graph = Graphics.create(bmpOrigin);
//Create a line of transparent pixels for later use
int[] aEmptyLine = new int[nWidth];
for(int x = 0; x < nWidth; x++)
aEmptyLine[x] = 0x00000000;
//Create two scaled bitmaps
Bitmap[] bmpScaled = new Bitmap[2];
for(int i = 0; i < 2; i++)
{
//Draw the bitmap on a white background first,
//then on a black background
graph.setColor((i == 0) ? Color.WHITE : Color.BLACK);
graph.fillRect(0, 0, nOriginWidth, nOriginHeight);
graph.drawBitmap(0, 0, nOriginWidth, nOriginHeight, bmpSrc, 0, 0);
//Create a new bitmap with the desired size
bmpScaled[i] = new Bitmap(nWidth, nHeight);
if(nAspectRatio == Bitmap.SCALE_TO_FIT)
{
//Set the alpha channel of all pixels to 0
//to ensure transparency is
//applied around the picture, if needed by the transformation
for(int y = 0; y < nHeight; y++)
bmpScaled[i].setARGB(aEmptyLine, 0, nWidth,
0, y, nWidth, 1);
}
//Scale the bitmap
bmpOrigin.scaleInto(bmpScaled[i], nFilterType, nAspectRatio);
}
//Prepare objects for final iteration
Bitmap bmpFinal = bmpScaled[0];
int[][] aPixelLine = new int[2][nWidth];
//Iterate every line of the two scaled bitmaps
for(int y = 0; y < nHeight; y++)
{
bmpScaled[0].getARGB(aPixelLine[0], 0, nWidth, 0, y, nWidth, 1);
bmpScaled[1].getARGB(aPixelLine[1], 0, nWidth, 0, y, nWidth, 1);
//Check every pixel one by one
for(int x = 0; x < nWidth; x++)
{
//If the pixel was untouched (alpha channel still at 0),
//keep it transparent
if(((aPixelLine[0][x] >> 24) & 0xff) == 0)
aPixelLine[0][x] = 0x00000000;
else
{
//Compute the alpha value based on the difference
//of intensity in the red channel
int nAlpha = ((aPixelLine[1][x] >> 16) & 0xff) -
((aPixelLine[0][x] >> 16) & 0xff) + 255;
if(nAlpha == 0)
aPixelLine[0][x] = 0x00000000; //Completely transparent
else if(nAlpha >= 255)
aPixelLine[0][x] |= 0xff000000; //Completely opaque
else
{
//Compute the value of the each channel one by one
int nRed = ((aPixelLine[0][x] >> 16) & 0xff);
int nGreen = ((aPixelLine[0][x] >> 8) & 0xff);
int nBlue = (aPixelLine[0][x] & 0xff);
nRed = (int)(255 +
(255.0 * ((double)(nRed-255)/(double)nAlpha)));
nGreen = (int)(255 +
(255.0 * ((double)(nGreen-255)/(double)nAlpha)));
nBlue = (int)(255 +
(255.0 * ((double)(nBlue-255)/(double)nAlpha)));
if(nRed < 0) nRed = 0;
if(nGreen < 0) nGreen = 0;
if(nBlue < 0) nBlue = 0;
aPixelLine[0][x] = nBlue | (nGreen<<8) |
(nRed<<16) | (nAlpha<<24);
}
}
}
//Change the pixels of this line to their final value
bmpFinal.setARGB(aPixelLine[0], 0, nWidth, 0, y, nWidth, 1);
}
return bmpFinal;
}
}
1
這裏是一個調整圖片大小,任何大小的方法:
public 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);
}
你要只是傳遞的寬度和高度 - 要在其中調整圖片的大小作爲參數。
您可以分別使用Display.getWidth()
& Display.getHeight()
獲得顯示屏的寬度和高度。
相關問題
- 1. 如何根據顯示屏幕的寬度和高度調整黑莓的圖像大小?
- 2. 根據寬度調整圖像大小
- 3. 根據UITableViewCell調整背景圖像的大小標籤的高度和寬度
- 4. 使用指定的高度和寬度調整圖像大小
- 5. Android:調整圖像寬度和高度以調整圖像大小
- 6. PHP圖像大小調整 - 設置高度和寬度自動
- 7. 如何根據高度調整圖像的大小,並根據高度進行調整
- 8. 圖像大小調整 - 寬度100%,最大高度
- 9. Google Python圖像庫 - 如何根據圖像寬度調整圖像大小?
- 10. 我如何使高度和寬度根據屏幕自動調整大小?
- 11. 如何在調整大小時計算圖像的寬度和高度值?
- 12. 使用PHP調整大小(寬度/高度)圖像
- 13. 如何根據div的寬度調整圖片大小?
- 14. 根據高度調整ImageView寬度
- 15. Android:將位圖的大小調整爲更大的像素寬度和高度
- 16. 圖像旋轉 - 基於圖像高度和寬度調整畫布大小
- 17. 根據內部圖像調整元素高度的大小
- 18. 根據父寬度調整圖像大小jQuery
- 19. 根據父寬度和高度調整子視圖的尺寸
- 20. 如何設置TinyMCE的最小調整大小寬度/高度?
- 21. 調整圖像的最大寬度和高度
- 22. jQuery根據動態角度調整圖像大小以適合div的寬度和高度
- 23. 根據內容寬度和高度調整彈出窗口的大小
- 24. 根據窗口高度調整圖像大小
- 25. 根據可用寬度調整圖像
- 26. imageflow滑塊圖像的寬度和大小調整大小
- 27. 最大高度和寬度與jQuery的大小調整
- 28. 如何調整圖像的高度和寬度在PHP笨
- 29. 如何使圖像的寬度自定義高度調整大小
- 30. 調整大小的圖像與確切的寬度和高度在php