List of usage examples for android.graphics Matrix postTranslate
public boolean postTranslate(float dx, float dy)
From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java
private void setBaseMatrix(Bitmap bitmap, Matrix matrix) { float viewWidth = getWidth(); float viewHeight = getHeight(); matrix.reset();//from ww w .ja v a2 s . c o m float widthScale = Math.min(viewWidth / (float) bitmap.getWidth(), 1.0f); float heightScale = Math.min(viewHeight / (float) bitmap.getHeight(), 1.0f); float scale; if (widthScale > heightScale) { scale = heightScale; } else { scale = widthScale; } matrix.setScale(scale, scale); matrix.postTranslate((viewWidth - ((float) bitmap.getWidth() * scale)) / 2F, (viewHeight - ((float) bitmap.getHeight() * scale)) / 2F); }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
/** * This function calculates a Image to Screen Transformation matrix * * @param reflectRotation set true if you want the rotation encoded * @return Image to Screen transformation matrix *//*from w w w . j av a 2 s .co m*/ protected Matrix getImageToScreenMatrix(boolean reflectRotation) { MasterImage master = MasterImage.getImage(); if (master.getOriginalBounds() == null) { return new Matrix(); } Matrix m = GeometryMathUtils.getImageToScreenMatrix(master.getPreset().getGeometryFilters(), reflectRotation, master.getOriginalBounds(), getWidth(), getHeight()); Point translate = master.getTranslation(); float scaleFactor = master.getScaleFactor(); m.postTranslate(translate.x, translate.y); m.postScale(scaleFactor, scaleFactor, getWidth() / 2.0f, getHeight() / 2.0f); return m; }
From source file:org.videolan.vlc.gui.MyFragment.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!VLCInstance.testCompatibleCPU(this)) { finish();// w ww.ja v a 2 s. c o m return; } /* Enable the indeterminate progress feature */ supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); /* Get the current version from package */ mVersionNumber = Config.VERSION_CODE; /* Check if it's the first run */ mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber; if (mFirstRun) { Editor editor = mSettings.edit(); editor.putInt(PREF_FIRST_RUN, mVersionNumber); Util.commitPreferences(editor); } mMediaLibrary = MediaLibrary.getInstance(); if (mMediaLibrary.getMediaItems().isEmpty()) { if (mSettings.getBoolean(PreferencesActivity.AUTO_RESCAN, true)) mMediaLibrary.scanMediaItems(); else mMediaLibrary.loadMedaItems(); } /*** Start initializing the UI ***/ setContentView(R.layout.my_fragment); // image1=(ImageView) findViewById(R.id.image); // AlphaAnimation animation = new AlphaAnimation(1.0,0.); // animation.setDuration(5000); //?5 // image1.startAnimation(animation); mDrawerLayout = (HackyDrawerLayout) findViewById(R.id.root_container); // mListView = (ListView)findViewById(R.id.sidelist); // mListView.setFooterDividersEnabled(true); // mSidebarAdapter = new SidebarAdapter(this); // mListView.setAdapter(mSidebarAdapter); initAudioPlayerContainerActivity(); //mSlidingPane.setActivated(false); if (savedInstanceState != null) { mCurrentFragment = savedInstanceState.getString("current"); // if (mCurrentFragment != null) //mSidebarAdapter.setCurrentFragment(mCurrentFragment); } /* Initialize UI variables */ mInfoLayout = findViewById(R.id.info_layout); mInfoProgress = (ProgressBar) findViewById(R.id.info_progress); mInfoText = (TextView) findViewById(R.id.info_text); /* Set up the action bar */ prepareActionBar(); /* Set up the sidebar click listener * no need to invalidate menu for now */ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (getSupportFragmentManager() .findFragmentById(R.id.fragment_placeholder) instanceof MediaBrowserFragment) ((MediaBrowserFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder)) .setReadyToDisplay(true); } }; // Set the drawer toggle as the DrawerListener // mDrawerLayout.setDrawerListener(mDrawerToggle); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); /* Reload the latest preferences */ reloadPreferences(); /*--------------------------------------------- */ titleList = new ArrayList<String>(); titleList.add("Libray"); titleList.add("File"); initIndView(); fragment1 = new VideoGridFragment(); // Fragment fragment2 = getSupportFragmentManager() // .findFragmentById(R.id.fragment_placeholder); // fragment2=new FileBrowserFragment(); fragment2 = new MyPageFragment1(); btn = (Button) findViewById(R.id.back_btn); pager = (ViewPager) findViewById(R.id.pager); pager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub Matrix matrix = new Matrix(); switch (arg0) { case 0: matrix.postTranslate(offset + (one - offset) * arg1, 0); break; case 1: matrix.postTranslate(one + (two - one) * arg1, 0); break; default: break; } cursor.setImageMatrix(matrix); } @Override public void onPageSelected(int currentID) { if (currentID == 0) { libray.setTextColor(Color.BLUE); file1.setTextColor(Color.BLACK); } else { libray.setTextColor(Color.BLACK); file1.setTextColor(Color.BLUE); } mCurrentViewID = currentID; } }); fragList = new ArrayList<Fragment>(); fragList.add(fragment1); fragList.add(fragment2); // FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); //// ft.replace(R.id.fragment_placeholder, new FileBrowserFragment(), mCurrentFragment); // ft.replace(R.id.fragment_placeholder, new FileBrowserFragment()); // ft.commit(); libray = (TextView) findViewById(R.id.libray); file1 = (TextView) findViewById(R.id.file1); file1.setOnClickListener(listener); libray.setOnClickListener(listener); MyFragmentPagerAdapter adapter2 = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragList, titleList); pager.setAdapter(adapter2); /*--------------------------------------------- */ }
From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java
/** * Setup the base matrix so that the image is centered and scaled properly. * ?BitmapRect?Matrix//from ww w.j av a2 s . c om * @author Linleja * @date 2014-4-29 * @param bitmap * @param matrix * @param selection */ private void setBaseMatrix(Bitmap bitmap, Matrix matrix, Rect selection) { if (selection == null) { return; } float viewWidth = selection.right - selection.left; float viewHeight = selection.bottom - selection.top; matrix.reset(); float widthRatio = viewWidth / (float) bitmap.getWidth(); float heighRatio = viewHeight / (float) bitmap.getHeight(); float scale = 1.0f; if (widthRatio > heighRatio) { scale = widthRatio; } else { scale = heighRatio; } matrix.setScale(scale, scale); matrix.postTranslate(((getWidth() - (float) bitmap.getWidth() * scale)) / 2F, ((getHeight() - (float) bitmap.getHeight() * scale)) / 2F); }
From source file:com.goka.flickableview.ImageViewTouchBase.java
protected void getProperBaseMatrix(Drawable drawable, Matrix matrix, RectF rect) { float w = mBitmapRect.width(); float h = mBitmapRect.height(); float widthScale, heightScale; matrix.reset();// w w w . j av a 2 s . c o m widthScale = rect.width() / w; heightScale = rect.height() / h; float scale = Math.min(widthScale, heightScale); matrix.postScale(scale, scale); matrix.postTranslate(rect.left, rect.top); float tw = (rect.width() - w * scale) / 2.0f; float th = (rect.height() - h * scale) / 2.0f; matrix.postTranslate(tw, th); printMatrix(matrix); }
From source file:com.example.PagerCoverFlow.PagerContainer.java
private void transformImageBitmap(ImageView child, Matrix imageMatrix, int rotationAngle) { mCamera.save();/*from w w w . ja v a 2 s .co m*/ // final Matrix imageMatrix = t.getMatrix();; final int imageHeight = child.getLayoutParams().height; final int imageWidth = child.getLayoutParams().width; final int rotation = Math.abs(rotationAngle); // mCamera.translate(0.0f, 0.0f, 100.0f); Log.i("Select", "imageWidth:" + imageWidth + " " + "imageHeight:" + imageHeight); //As the angle of the view gets less, zoom in // if ( rotation < mMaxRotationAngle ) { float zoomAmount = (float) (mMaxZoom + (rotation * 1.5)); Log.i("Select", "rotation:" + rotation + " zoomAmount:" + zoomAmount); mCamera.translate(0.0f, 0.0f, zoomAmount); } //Alpha int alphaVal = 255 - rotation * 3; // child.setAlpha(alphaVal); //[0,255] child.getDrawable().setAlpha(alphaVal); // mCamera.rotateY(rotationAngle); mCamera.getMatrix(imageMatrix); imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2)); imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2)); mCamera.restore(); float[] values = new float[9]; imageMatrix.getValues(values); float globalX = values[Matrix.MTRANS_X]; float globalY = values[Matrix.MTRANS_Y]; // float width = values[Matrix.MSCALE_X]*CommonValue.menuWidth ; // float height = values[Matrix.MSCALE_Y]*CommonValue.menuWidth; values[Matrix.MSCALE_X] = 2; values[Matrix.MSCALE_Y] = 2; imageMatrix.setValues(values); }
From source file:org.navitproject.navit.NavitGraphics.java
protected void draw_image_warp(Paint paint, int count, int p0x, int p0y, int p1x, int p1y, int p2x, int p2y, Bitmap bitmap) {/*from www . ja v a 2 s . c o m*/ float width; float scale; float deltaY; float deltaX; float angle; Matrix matrix; if (count == 3) { matrix = new Matrix(); deltaX = p1x - p0x; deltaY = p1y - p0y; width = (float) (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY))); angle = (float) (Math.atan2(deltaY, deltaX) * 180d / Math.PI); scale = width / bitmap.getWidth(); matrix.preScale(scale, scale); matrix.postTranslate(p0x, p0y); matrix.postRotate(angle, p0x, p0y); draw_canvas.drawBitmap(bitmap, matrix, paint); } }
From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java
@OnClick(R.id.item_save) void onSaveClicked() { if (!mCropData.isPresent() || mSaving || (mCrop == null)) { return;/*from w ww . j av a 2 s . c o m*/ } mSaving = true; Util.startBackgroundJob(this, null, getText(R.string.cropping_image).toString(), new Runnable() { public void run() { try { float scale = 1f / mCropData.get().getScaleResult().getScaleFactor(); Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(scale, scale); final float[] trapezoid = mCrop.getTrapezoid(); final RectF perspectiveCorrectedBoundingRect = new RectF( mCrop.getPerspectiveCorrectedBoundingRect()); scaleMatrix.mapRect(perspectiveCorrectedBoundingRect); Box bb = new Box((int) perspectiveCorrectedBoundingRect.left, (int) perspectiveCorrectedBoundingRect.top, (int) perspectiveCorrectedBoundingRect.width(), (int) perspectiveCorrectedBoundingRect.height()); Pix pix8 = Convert.convertTo8(mPix); mPix.recycle(); Pix croppedPix = Clip.clipRectangle2(pix8, bb); if (croppedPix == null) { throw new IllegalStateException(); } pix8.recycle(); scaleMatrix.postTranslate(-bb.getX(), -bb.getY()); scaleMatrix.mapPoints(trapezoid); final float[] dest = new float[] { 0, 0, bb.getWidth(), 0, bb.getWidth(), bb.getHeight(), 0, bb.getHeight() }; Pix bilinear = Projective.projectiveTransform(croppedPix, dest, trapezoid); if (bilinear == null) { bilinear = croppedPix; } else { croppedPix.recycle(); } if (mRotation != 0 && mRotation != 4) { Pix rotatedPix = Rotate.rotateOrth(bilinear, mRotation); bilinear.recycle(); bilinear = rotatedPix; } if (bilinear == null) { throw new IllegalStateException(); } Intent result = new Intent(); OCR.savePixToCacheDir(CropImageActivity.this, bilinear.copy()); result.putExtra(DocumentGridActivity.EXTRA_NATIVE_PIX, bilinear.getNativePix()); setResult(RESULT_OK, result); } catch (IllegalStateException e) { setResult(RESULT_CANCELED); } finally { finish(); } } }, mHandler); }
From source file:com.codegarden.nativenavigation.JuceActivity.java
public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds(boundsF, true);/*from www . j a va 2s . c o m*/ matrix.mapRect(boundsF); boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max(1, bounds.height()); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); matrix.postTranslate(-bounds.left, -bounds.top); c.setMatrix(matrix); c.drawPath(p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded]; bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:cl.monsoon.s1next.widget.PhotoView.java
/** * Gets a bitmap of the cropped region. If cropping is not enabled, returns {@code null}. *//*from ww w . j a v a 2 s . c o m*/ public Bitmap getCroppedPhoto() { if (!mAllowCrop) { return null; } final Bitmap croppedBitmap = Bitmap.createBitmap((int) CROPPED_SIZE, (int) CROPPED_SIZE, Bitmap.Config.ARGB_8888); final Canvas croppedCanvas = new Canvas(croppedBitmap); // scale for the final dimensions final int cropWidth = mCropRect.right - mCropRect.left; final float scaleWidth = CROPPED_SIZE / cropWidth; final float scaleHeight = CROPPED_SIZE / cropWidth; // translate to the origin & scale final Matrix matrix = new Matrix(mDrawMatrix); matrix.postTranslate(-mCropRect.left, -mCropRect.top); matrix.postScale(scaleWidth, scaleHeight); // draw the photo if (mDrawable != null) { croppedCanvas.concat(matrix); mDrawable.draw(croppedCanvas); } return croppedBitmap; }