Postingan

Menampilkan postingan dengan label Graphics Code

Graphics Image From Layout

//onCreate } private void storeImage(Bitmap image) { java.io.File pictureFile = new java.io.File(getExternalCacheDir() + "/image.jpg"); if (pictureFile == null) { Log.d("MainActivity", "Error creating media file, check storage permissions: "); return; } try { java.io.FileOutputStream fos = new java.io.FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } catch (java.io.FileNotFoundException e) { Log.d("MainActivity", "File not found: " + e.getMessage()); } catch (java.io.IOException e) { Log.d("MainActivity", "Error accessing file: " + e.getMessage()); } Intent iten = new Intent(android.content.Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg"))); startActivity(Intent.createChooser(iten, "Поделиться/сохранить")); } private Bitmap getBitmapFromView(View...

Graphics Bitmap Shader

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.pattern); Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); textview1.setLayerType(View.LAYER_TYPE_SOFTWARE, null); textview1.getPaint().setShader(shader);

Graphics Bitmap To String

//Bitmap to String: public String BitMapToString(Bitmap bitmap){       java.io.ByteArrayOutputStream baos=new  java.io.ByteArrayOutputStream();       bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);       byte [] arr=baos.toByteArray();       String result=Base64.encodeToString(arr, Base64.DEFAULT);       return result; } //String to Bitmap: public Bitmap StringToBitMap(String image){    try{       byte [] encodeByte=Base64.decode(image,Base64.DEFAULT);       Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);       return bitmap;    }catch(Exception e){       e.getMessage();       return null;    }  }

Graphics Bitmap Compression

android.graphics.drawable.Drawable drawable = getDrawable(R.drawable.image); Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable)drawable).getBitmap(); //Source imageview1.setImageBitmap(bitmap); java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,50,stream); byte[] byteArray = stream.toByteArray(); Bitmap compressedBitmap = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length); //Result 50% Quality imageview2.setImageBitmap(compressedBitmap);

Graphics DP to Pixel

//OnButton int dp_first = 25; int dp_second = 15; int dp_third = 29; int dp_fourth = 41; Activity activity = MainActivity.this; textview1.setText("DIP/DP to Pixels conversion... "); textview1.setText(textview1.getText()+ ""+dp_first+ "dp = "+ getPixelsFromDPs(activity,dp_first) + "pixels "+dp_second+ "dp = "+ getPixelsFromDPs(activity,dp_second) + "pixels "+dp_third+ "dp = "+ getPixelsFromDPs(activity,dp_third) + "pixels "+dp_fourth+ "dp = "+ getPixelsFromDPs(activity,dp_fourth) + "pixels "); //onCreate public static int getPixelsFromDPs(Activity activity, int dps){ android.content.res.Resources r = activity.getResources(); int  px = (int) (android.util.TypedValue.applyDimension(android.util.TypedValue.COMPLEX_UNIT_DIP, dps, r.getDisplayMetrics())); return px; } #Pixel to DP //OnButton int pixels_first = 37; int pixels_second = 22; int pixels_third = 43; int pixels_fourth = 61; Context c...

Graphics Debos Effect

EmbossMaskFilter filter = new EmbossMaskFilter(      new float[]{ 0f, -1f, 0.5f }, // direction of the light source      0.8f, // ambient light between 0 to 1      13, // specular highlights      7.0f // blur before applying lighting ); textview1.setLayerType(View.LAYER_TYPE_SOFTWARE,null); textview1.getPaint().setMaskFilter(filter);

Graphics Draw Bitmap On Canvas

//Add Private private Context mContext; private android.content.res.Resources mResources; //onCreate mContext = getApplicationContext(); mResources = getResources(); //onButton // Bitmap to draw on the canvas Bitmap bitmap = BitmapFactory.decodeResource(       mResources,       R.drawable.icon ); // Define an offset value between canvas and bitmap int offset = 50; // Initialize a new Bitmap to hold the source bitmap Bitmap dstBitmap = Bitmap.createBitmap(          bitmap.getWidth() + offset * 2, // Width          bitmap.getHeight() + offset * 2, // Height          Bitmap.Config.ARGB_8888 // Config ); // Initialize a new Canvas instance Canvas canvas = new Canvas(dstBitmap); // Draw a solid color on the canvas as background canvas.drawColor(Color.LTGRAY); canvas.drawBitmap(        bitmap, // Bitmap        offset, // Left       ...

Graphics Draw Finger

dv = new DrawingView(this); linear1.addView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); } DrawingView dv; private Paint mPaint; private Canvas mCanvas; public class DrawingView extends View { public int width; public int height; private Bitmap mBitmap; private Path mPath; private Paint mBitmapPaint; Context context; private Paint circlePaint; private Path circlePath; public DrawingView(Context c) { super(c); context=c; mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); circlePaint = new Paint(); circlePath = new Path(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); } @Override protected void onSizeChanged(int w, int h, int oldw, int ...

Graphics Drawable

imageview1.setBackground(Drawables.getSelectableDrawableFor(Color.parseColor("#404040"))); imageview1.setClickable(true); } public static class Drawables {     public static android.graphics.drawable.Drawable getSelectableDrawableFor(int color) {         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {             android.graphics.drawable.StateListDrawable stateListDrawable = new android.graphics.drawable.StateListDrawable();             stateListDrawable.addState(                 new int[]{android.R.attr.state_pressed},                 new android.graphics.drawable.ColorDrawable(Color.parseColor("#ffffff"))             );             stateListDrawable.addState(                 new int[]{android.R.attr.stat...

Graphics Fit Device

Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); try { display.getRealSize(size); } catch (NoSuchMethodError err) { display.getSize(size); } int width = size.x; int height = size.y; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int)(width), LinearLayout.LayoutParams.MATCH_PARENT); layout1.setLayoutParams(lp);

Graphics Font Assets

textview1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/mobile_clubz.ttf"), 0);

Graphics Font External

String path = getExternalCacheDir() + "/myfont.ttf"; //let us copy the font on private storage. copyFiletoExternalStorage(R.raw.myfont2, "myfont.ttf"); //let us load the font Typeface myTypeface = Typeface.createFromFile(path); //let us set the font to text view  txt2.setTypeface(myTypeface); } private void copyFiletoExternalStorage(int resourceId, String resourceName){         String pathSDCard = getExternalCacheDir() + "/myfont.ttf";//Environment.getExternalStorageDirectory() + "/Android/data/" + resourceName;         try{             java.io.InputStream in = getResources().openRawResource(resourceId);             java.io.FileOutputStream out = null;             out = new java.io.FileOutputStream(pathSDCard);             byte[] buff = new byte[1024];             int read = 0;     ...

Graphics Gradient Color

//Gradient Code Starts Here int[] colors = {Color.rgb(138,41,81),Color.rgb(41,53,158)}; android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation.BR_TL, colors); gd.setCornerRadius(0f); gd.setStroke(0,Color.WHITE); if(android.os.Build.VERSION.SDK_INT >= 16) {linear1.setBackground(gd); } else {linear1.setBackgroundDrawable(gd);} //End of Gradient Generator

Graphics Image Base64

//on onCreate } private static final String STATE_IMAGE_URI = "STATE_IMAGE_URI"; private Uri imageUri; public void onSaveInstanceState(Bundle state) { super.onSaveInstanceState(state); if (imageUri != null ) { state.putParcelable(STATE_IMAGE_URI, imageUri); } } public void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); if(state == null || !state.containsKey(STATE_IMAGE_URI)) return; setImage((Uri)state.getParcelable(STATE_IMAGE_URI)); } private static final int IMAGE_REQUEST_CODE = 9; private void chooseImage() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select picture"), IMAGE_REQUEST_CODE); } public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode != IMAGE_REQUEST_CODE) { return; } if (resultCode != Activity.RESULT_OK) { ret...

Graphics Image Color Filter

//set color filter on image _view.setColorFilter(Color.argb(255,0,0,0)); //remove color filter from image _view.clearColorFilter();

Graphics Image Croper

private void performCrop(Uri picUri) {     try {         Intent cropIntent = new Intent("com.android.camera.action.CROP");         // indicate image type and Uri         cropIntent.setDataAndType(picUri, "image/*");         // set crop properties here         cropIntent.putExtra("crop", true);         // indicate aspect of desired crop         cropIntent.putExtra("aspectX", 1);         cropIntent.putExtra("aspectY", 1);         // indicate output X and Y         cropIntent.putExtra("outputX", 128);         cropIntent.putExtra("outputY", 128);         // retrieve data on return         cropIntent.putExtra("return-data", true);         // start the activity - we handle returning in onActivityResult ...

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation