Last active
December 21, 2015 05:09
-
-
Save kimukou/6255166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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