Skip to content

Instantly share code, notes, and snippets.

@kimukou
Last active December 21, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimukou/6255166 to your computer and use it in GitHub Desktop.
Save kimukou/6255166 to your computer and use it in GitHub Desktop.
private static final float DEF_BASE_SCALE_X = 320.0f;
private static final float DEF_BASE_SCALE_Y = 240.0f;
private static final float DEF_BASE_HOSEI_X = 20.0f;
private static final float DEF_BASE_HOSEI_Y = 20.0f;
ImageView iv = (ImageView) gDlg.findViewById(R.id.gh_image);
if (sds.get(0).getData() != null) {
cleanupView(iv); //ivについてる画像情報を破棄する関数
FlotDraw fd = new FlotDraw(sds, null, null);
//画面比でサイズを設定する。S4だとなんか伸びない☆
//int width = iv.getWidth() == 0 ? 640:iv.getWidth();
//int height = iv.getHeight()==0 ? 480:iv.getHeight();
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
float scale = (metrics.widthPixels /metrics.density) / DEF_BASE_SCALE_X ;
float m_density = metrics.density * scale;
int width = (int)(m_density * (DEF_BASE_SCALE_X -DEF_BASE_HOSEI_X) );
int height = (int)(m_density * (DEF_BASE_SCALE_Y -DEF_BASE_HOSEI_Y) );
//背景色を設定するグラフLibraryなので不透明でOK(S4対策)☆
Bitmap.Config conf = Bitmap.Config.RGB_565;//Bitmap.Config.ARGB_4444;
Bitmap root_bitmap = null;
Bitmap bitmap = null;
try {
root_bitmap = Bitmap.createBitmap(width, height, conf);
Canvas canvas = new Canvas(bitmap);
fd.draw(canvas, width, height);
//一度PNG圧縮したデータ作成(S4対策) ☆
int size = root_bitmap.getWidth() * root_bitmap.getHeight();
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
root_bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] bytSig =out.toByteArray();
out.close();
bitmap = BitmapFactory.decodeByteArray(bytSig, 0, bytSig.length);
//[NOTE]S4だとsetImageBitmapの方でないと超小さく表示される☆
if(tx instanceof ImageView ){
((ImageView)tx).setImageBitmap(bitmap);
}
else{
iv.setBackgroundDrawable(new BitmapDrawable(bitmap));
}
}
catch (Exception e) {
if(bitmap != null)bitmap.recycle();
}
finally{
if(root_bitmap!=null)root_bitmap.recycle();
System.gc();
System.runFinalization();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment