Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat ImageFormat should I use?
    primarykey
    data
    text
    <p>I'm getting image with</p> <pre><code>Graphics graphics = game.getGraphics(); Images.menu = graphics.newImage("image.png", ImageFormat.RGB565); </code></pre> <p>but the picture doesn't look good. You can see transitions if picture have gradient. Except RGB565, there is also ARGB4444 and ARGB8888, but they are even worse than RGB565.</p> <p>Is there any way that the image look the way it actually looks in folder Images?</p> <p>Graphics.java:</p> <pre><code>import android.graphics.Paint; public interface Graphics { public static enum ImageFormat { ARGB8888, ARGB4444, RGB565 } public Image newImage(String fileName, ImageFormat format); public void clearScreen(int color); public void drawLine(int x, int y, int x2, int y2, int color); public void drawRect(int x, int y, int width, int height, int color); public void drawImage(Image image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight); public void drawImage(Image Image, int x, int y); void drawString(String text, int x, int y, Paint paint); public int getWidth(); public int getHeight(); public void drawARGB(int i, int j, int k, int l); } </code></pre> <p>AndroidGraphics.java:</p> <pre><code>import java.io.IOException; import java.io.InputStream; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.BitmapFactory.Options; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.Rect; import com.n.framework.Graphics; import com.n.framework.Image; public class AndroidGraphics implements Graphics { AssetManager assets; Bitmap frameBuffer; Canvas canvas; Paint paint; Rect srcRect = new Rect(); Rect dstRect = new Rect(); public AndroidGraphics(AssetManager assets, Bitmap frameBuffer) { this.assets = assets; this.frameBuffer = frameBuffer; this.canvas = new Canvas(frameBuffer); this.paint = new Paint(); } @Override public Image newImage(String fileName, ImageFormat format) { Config config = null; if (format == ImageFormat.RGB565) config = Config.RGB_565; else if (format == ImageFormat.ARGB4444) config = Config.ARGB_4444; else config = Config.ARGB_8888; Options options = new Options(); options.inPreferredConfig = config; InputStream in = null; Bitmap bitmap = null; try { in = assets.open(fileName); bitmap = BitmapFactory.decodeStream(in, null, options); if (bitmap == null) throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } catch (IOException e) { throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } if (bitmap.getConfig() == Config.RGB_565) format = ImageFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = ImageFormat.ARGB4444; else format = ImageFormat.ARGB8888; return new AndroidImage(bitmap, format); } @Override public void clearScreen(int color) { canvas.drawRGB((color &amp; 0xff0000) &gt;&gt; 16, (color &amp; 0xff00) &gt;&gt; 8, (color &amp; 0xff)); } @Override public void drawLine(int x, int y, int x2, int y2, int color) { paint.setColor(color); canvas.drawLine(x, y, x2, y2, paint); } @Override public void drawRect(int x, int y, int width, int height, int color) { paint.setColor(color); paint.setStyle(Style.FILL); canvas.drawRect(x, y, x + width - 1, y + height - 1, paint); } @Override public void drawARGB(int a, int r, int g, int b) { paint.setStyle(Style.FILL); canvas.drawARGB(a, r, g, b); } @Override public void drawString(String text, int x, int y, Paint paint){ canvas.drawText(text, x, y, paint); } public void drawImage(Image Image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) { srcRect.left = srcX; srcRect.top = srcY; srcRect.right = srcX + srcWidth; srcRect.bottom = srcY + srcHeight; dstRect.left = x; dstRect.top = y; dstRect.right = x + srcWidth; dstRect.bottom = y + srcHeight; canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null); } @Override public void drawImage(Image Image, int x, int y) { canvas.drawBitmap(((AndroidImage)Image).bitmap, x, y, null); } public void drawScaledImage(Image Image, int x, int y, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight){ srcRect.left = srcX; srcRect.top = srcY; srcRect.right = srcX + srcWidth; srcRect.bottom = srcY + srcHeight; dstRect.left = x; dstRect.top = y; dstRect.right = x + width; dstRect.bottom = y + height; canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null); } @Override public int getWidth() { return frameBuffer.getWidth(); } @Override public int getHeight() { return frameBuffer.getHeight(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload