簡體   English   中英

有人知道如何顯示BitmapField嗎?

[英]Does anyone know how to display a BitmapField?

我有一個將圖像編碼為位圖的代碼。 但是我不確定如何在屏幕上顯示它。 順便說一句,我正在使用Blackberry JavaME。 這是我用來編碼圖像的代碼。 這是我可以用來從SD卡中獲取圖像並將其顯示在屏幕上的方法嗎?

FileConnection conn = 
    (FileConnection)Connector.open("image1.png",Connector.READ_WRITE);
if(conn.exists()) {
    InputStream is = conn.openInputStream();
    BitmapField bitmap = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int ch;
    while ((ch = is.read()) != -1)
    {
        baos.write(ch);
    }
    byte imageData[] = baos.toByteArray();
    bitmap = new BitmapField(
        EncodedImage.createEncodedImage(imageData, 0, imageData.length).getBitmap());
    add(bitmap);
}

Secko是正確的,您可以覆蓋繪畫,但我認為您會陷入困境,因為尚未創建ui應用程序。

這是一個用於顯示位圖字段的非常簡單的ui應用程序示例,如果要精確復制它,則將需要src下的images文件夾,其中包含image.png。

這是從SDK附帶的HelloWorldDemo修改而來的。 我建議如果您剛開始,請查看文件夾中的示例。 \\ plugins \\ net.rim.ejde.componentpack5.0.0_5.0.0.25 \\ components \\ samples \\

祝好運

射線

public class DisplayBitmaps extends UiApplication
{
    public static void main(String[] args)
    {
        DisplayBitmaps theApp = new DisplayBitmaps();       
        theApp.enterEventDispatcher();
    }

    public DisplayBitmaps()
    {        
        pushScreen(new DisplayBitmapsScreen());
    }    
}

final class DisplayBitmapsScreen extends MainScreen
{
    DisplayBitmapsScreen()
    {    
     Bitmap bitmap = EncodedImage.getEncodedImageResource("images/image.png").getBitmap();
     BitmapField bitmapField = new BitmapField(bitmap);
        add(bitmapField);
    }

    public void close()
    {  
        super.close();
    }   
}

編輯圖像何時在sdcard上

DisplayBitmapsScreen()
{    
 //Bitmap bitmap = EncodedImage.getEncodedImageResource("images/image.png").getBitmap();
 try {
  FileConnection fc = (FileConnection) Connector.open("file:///SDCard/BlackBerry/pictures/image.png");
  if (fc.exists()) {
   byte[] image = new byte[(int) fc.fileSize()];
   InputStream inStream = fc.openInputStream();
   inStream.read(image);
   inStream.close();
   EncodedImage encodedImage = EncodedImage.createEncodedImage(image, 0, -1);
   BitmapField bitmapField = new BitmapField(encodedImage.getBitmap());
   fc.close();
   add(bitmapField);
  }
 } catch (Exception e) { System.out.println("EXCEPTION " + e); }
}

在Field或任何擴展Field類中覆蓋塗料也可以顯示圖像,但是我從Secko的示例中並不真正理解他將在何處顯示圖像,因此我在下面的示例中包括了drawImage。

protected void paint(Graphics graphics) {
   graphics.drawImage(x, y, width, height, image, frameIndex, left, top);
   super.paint(graphics);
}

您可以執行以下操作:

油漆(圖形g);

也許在一個函數中:

protected void DrawStuff(Graphics g) {              
    this.paint(g);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM