@Override public Pixmap newPixmap(String fileName, PixmapFormat format) { Config config = null; if (format == PixmapFormat.RGB565) config = Config.RGB_565; else if (format == PixmapFormat.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); 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 = PixmapFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = PixmapFormat.ARGB4444; else format = PixmapFormat.ARGB8888; return new AndroidPixmap(bitmap, format); }
public BitmapDataSrc(Bitmap bitmap) { this.bitmap = bitmap; this.w = bitmap.getWidth(); this.h = bitmap.getHeight(); this.nc = 3; this.nomRangeBits = 8; }
public byte[] getTileImageData(int x, int y, int zoom) { mStream.reset(); Matrix matrix = new Matrix(mBaseMatrix); float scale = (float) (Math.pow(2, zoom) * mScale); matrix.postScale(scale, scale); matrix.postTranslate(-x * mDimension, -y * mDimension); mBitmap.eraseColor(Color.TRANSPARENT); Canvas c = new Canvas(mBitmap); c.setMatrix(matrix); // NOTE: Picture is not thread-safe. synchronized (mSvgPicture) { mSvgPicture.draw(c); } BufferedOutputStream stream = new BufferedOutputStream(mStream); mBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); try { stream.close(); } catch (IOException e) { Log.e(TAG, "Error while closing tile byte stream."); e.printStackTrace(); } return mStream.toByteArray(); }
private void drawFooter(Canvas canvas) { final ZLView view = ZLApplication.Instance().getCurrentView(); final ZLView.FooterArea footer = view.getFooterArea(); if (footer == null) { myFooterBitmap = null; return; } if (myFooterBitmap != null && (myFooterBitmap.getWidth() != getWidth() || myFooterBitmap.getHeight() != footer.getHeight())) { myFooterBitmap = null; } if (myFooterBitmap == null) { myFooterBitmap = Bitmap.createBitmap(getWidth(), footer.getHeight(), Bitmap.Config.RGB_565); } final ZLAndroidPaintContext context = new ZLAndroidPaintContext( new Canvas(myFooterBitmap), getWidth(), footer.getHeight(), view.isScrollbarShown() ? getVerticalScrollbarWidth() : 0); footer.paint(context); canvas.drawBitmap(myFooterBitmap, 0, getHeight() - footer.getHeight(), myPaint); }
private void drawPlaceHolder(Canvas canvas) { placeholderPaint.setColor(layout.placeHolderColor); placeholderTextPaint.setAlpha(255); placeholderPaint.setAlpha(255); avatarPaint.setAlpha(255); rect.set( layout.layoutAvatarLeft, layout.layoutAvatarTop, layout.layoutAvatarLeft + layout.layoutAvatarWidth, layout.layoutAvatarTop + layout.layoutAvatarWidth); canvas.drawRect(rect, placeholderPaint); if (layout.usePlaceholder) { canvas.drawText( layout.placeHolderName, layout.placeholderLeft, layout.placeholderTop, placeholderTextPaint); } else { rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight()); canvas.drawBitmap(placeholder, rect2, rect, avatarPaint); } }
// ============================================================================== 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); matrix.mapRect(boundsF); boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = 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; }
public SliderField( Bitmap thumb, Bitmap sliderBackground, Bitmap sliderBackgroundFocus, int numStates, int initialState, int xLeftBackMargin, int xRightBackMargin, long style) { super(style); if (initialState > numStates || numStates < 2) {} _imageThumb = thumb; _imageSlider = sliderBackground; _imageSliderFocus = sliderBackgroundFocus; _numStates = numStates; setState(initialState); _xLeftBackMargin = xLeftBackMargin; _xRightBackMargin = xRightBackMargin; _rop = _imageSlider.hasAlpha() ? Graphics.ROP_SRC_ALPHA : Graphics.ROP_SRC_COPY; _thumbWidth = thumb.getWidth(); _thumbHeight = thumb.getHeight(); initBitmaps(); }
/** * Drawing src bitmap to dest bitmap with applied mask. * * @param src source bitmap * @param mask bitmap mask * @param dest destination bitmap * @param clearColor clear color */ public static void drawMasked(Bitmap src, Drawable mask, Bitmap dest, int clearColor) { clearBitmap(dest, clearColor); Canvas canvas = new Canvas(dest); canvas.drawBitmap( src, new Rect(0, 0, src.getWidth(), src.getHeight()), new Rect(0, 0, dest.getWidth(), dest.getHeight()), new Paint(Paint.FILTER_BITMAP_FLAG)); if (mask instanceof BitmapDrawable) { ((BitmapDrawable) mask) .getPaint() .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); } else if (mask instanceof NinePatchDrawable) { ((NinePatchDrawable) mask) .getPaint() .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); } else { throw new RuntimeException("Supported only BitmapDrawable or NinePatchDrawable"); } mask.setBounds(0, 0, mask.getIntrinsicWidth(), mask.getIntrinsicHeight()); mask.draw(canvas); canvas.setBitmap(null); }
public void render(Bitmap screen, float delta_time, Rasterizer triangle) { // FOV // float ztan = (float) Math.tan(Math.toRadians(80.0)); float ztan = 1; screen.paint((byte) 0x00, (byte) 0x00, (byte) 0x00); float halfWidth = screen.getWidth() / 2.0f; float halfHeight = screen.getHeight() / 2.0f; for (int i = 0; i < 1; i++) { drop_z -= delta_time * cspeed; if (drop_z <= 0) spawn_drop(2); // Multiplying the position by (size/2) and then adding (size/2) // remaps the positions from range (-1, 1) to (0, size) int x = (int) ((drop_x / (drop_z * ztan)) * halfWidth + halfWidth); int y = (int) ((drop_y / (drop_z * ztan)) * halfHeight * halfHeight); if (x < 0 || x > screen.getWidth() || y < 0 || y > screen.getHeight()) { spawn_drop(i); } else { Vertex v1 = new Vertex(x, y); spawn_drop(i); x = (int) ((drop_x / (drop_z * ztan)) * halfWidth + halfWidth); y = (int) ((drop_y / (drop_z * ztan)) * halfHeight * halfHeight); Vertex v2 = new Vertex(x, y); spawn_drop(i); x = (int) ((drop_x / (drop_z * ztan)) * halfWidth + halfWidth); y = (int) ((drop_y / (drop_z * ztan)) * halfHeight * halfHeight); Vertex v3 = new Vertex(x, y); triangle.rasterize(v1, v2, v3); } } }
public TrackingPatternView(Context context, AttributeSet attributeset) { super(context, attributeset); mTexture = BitmapFactory.decodeResource(getResources(), 0x108056f); mTextureWidth = mTexture.getWidth(); mTextureHeight = mTexture.getHeight(); mPaint = new Paint(); mPaint.setDither(false); }
public static Bitmap rotateBmp(Bitmap bmp, int angle) { int width = bmp.getWidth(); int height = bmp.getHeight(); Matrix matrix = new Matrix(); matrix.postRotate(angle); return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); }
/** 初始化Bitmap */ private void createBitmaps() { mSky = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sky); mSky = Bitmap.createScaledBitmap(mSky, mScreenWidth, mSkyHeight, true); mTown = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.buildings); mTown = Bitmap.createScaledBitmap(mTown, mScreenWidth, mTownHeight, true); mSun = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sun); mSun = Bitmap.createScaledBitmap(mSun, mSunSize, mSunSize, true); }
/** scale image */ public static Bitmap scaleImage(Bitmap org, float scaleWidth, float scaleHeight) { if (org == null) { return null; } Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(org, 0, 0, org.getWidth(), org.getHeight(), matrix, true); }
public TiledBitmapCanvas(Bitmap bitmap, int tileSize, int maxVersions) { mWidth = bitmap.getWidth(); mHeight = bitmap.getHeight(); mConfig = bitmap.getConfig(); mTileSize = tileSize; mMaxVersions = maxVersions; load(bitmap); }
private static Bitmap convertToAlphaMask(Bitmap b) { Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8); Canvas c = new Canvas(a); Paint pt = new Paint(); pt.setColorFilter(new ColorMatrixColorFilter(MASK)); c.drawBitmap(b, 0.0f, 0.0f, pt); return a; }
private void copy(Bitmap src, int x, int y, int width, int height, Bitmap dest) { int[] argbData = new int[width * height]; src.getARGB(argbData, 0, width, x, y, width, height); for (int tx = 0; tx < dest.getWidth(); tx += width) { for (int ty = 0; ty < dest.getHeight(); ty += height) { dest.setARGB(argbData, 0, width, tx, ty, width, height); } } }
public final void makeUsing(final Bitmap aBitmap) { // #if DEBUG Assert.isFalse("not made", myHasTextureIdFlag); // #endif myWidth = aBitmap.getWidth(); myHeight = aBitmap.getHeight(); makeOpenglTexture(aBitmap); }
private void makeOpenglTexture(final Bitmap aBitmapARGB32) { myWidth = aBitmapARGB32.getWidth(); myHeight = aBitmapARGB32.getHeight(); myOglTextureId = myUtilities.makeNewOpenglTexture(); myHasTextureIdFlag = true; myUtilities.setTexturePixels(aBitmapARGB32); }
public synchronized void resize(int h, int w) { if (w <= 0 || h <= 0) { bgBuffer = null; fgBuffer = null; } else { bgBuffer = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); fgBuffer = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); } }
public boolean getElementTouched(int x, int y) { if ((mX < x && x < mX + mBitmap.getWidth()) && (mY < y && y < mY + mBitmap.getHeight()) && this.head) { return true; } else { return false; } }
public byte[] compressBitmapToBytes(String filePath, int reqWidth, int reqHeight, int quality) { Bitmap bitmap = getSmallBitmap(filePath, reqWidth, reqHeight); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); byte[] bytes = baos.toByteArray(); bitmap.recycle(); Log.i(TAG, "Bitmap compressed success, size: " + bytes.length); return bytes; }
public static Bitmap zoomImage(Bitmap bmp, double newWidth, double newHeight) { float width = bmp.getWidth(); float height = bmp.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; matrix.postScale(scaleWidth, scaleHeight); Bitmap bitmap = Bitmap.createBitmap(bmp, 0, 0, (int) width, (int) height, matrix, true); return bitmap; }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int i, j, k; System.out.println("Starting painting"); // draw sets if (firstTimeAround) { drawSet(g2); render(); viewer.save("final_product_full.png"); firstTimeAround = false; } // render(); /* for(i=0;i<viewer.getWidth();i++){ for(j=0;j<viewer.getHeight();j++){ viewer.setPixel(i,j,Color3.BLACK); } } */ g2.setBackground(Color.BLACK); // if(newRender){ for (i = minX; i < maxX; i++) { // System.out.println("line "+i); for (j = minY; j < maxY; j++) { g2.setColor( new Color( (float) viewer.getPixel(i, j).getR(), (float) viewer.getPixel(i, j).getG(), (float) viewer.getPixel(i, j).getB())); // g2.drawLine(i,j,1,1); Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1); g2.fill(node_circ); g2.setColor(Color.BLACK); // if(j*scale<viewer.getHeight()){ // j=0;//viewer.getHeight(); // } } // if(i*scale<viewer.getWidth()){ // i=0;//viewer.getWidth(); // } } // g2.drawImage(viewer.1) newRender = false; // } System.out.println("end painting"); }
// Similar to TextFields layout() protected void layout(int width, int height) { if (width < 0 || height < 0) throw new IllegalArgumentException(); // We'll take all we can get _totalWidth = width; // The largest of the two image heights _totalHeight = Math.max(_imageSlider.getHeight(), _imageThumb.getHeight()); setExtent(_totalWidth, _totalHeight); }
/** * Rotates image by the specified number of degrees clockwise. Cycles from 0 to 360 degrees. * * @param degrees Integer specifying the number of degrees to rotate. */ public void rotateImage(int degrees) { Matrix matrix = new Matrix(); matrix.postRotate(degrees); mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true); setImageBitmap(mBitmap); mDegreesRotated += degrees; mDegreesRotated = mDegreesRotated % 360; }
public BitmapButtonField(Bitmap normalState, Bitmap focusState, long style) { super(Field.FOCUSABLE | style); if ((normalState.getWidth() != focusState.getWidth()) || (normalState.getHeight() != focusState.getHeight())) { throw new IllegalArgumentException("Image sizes don't match"); } _bitmaps = new Bitmap[] {normalState, focusState}; }
private Bitmap makeProperBitmap(final Bitmap aBitmap, final int aWidth, final int aHeight) { final Bitmap bitmap = Bitmap.createBitmap(aWidth, aHeight, Bitmap.Config.ARGB_8888); myTextureCloneCanvas.setBitmap(bitmap); myTextureCloneCanvas.drawBitmap(aBitmap, 0, 0, myTextureClonePaint); // #if DEBUG Log.debug("created proper texture bitmap"); Log.debug("bitmap size: {}x{}", aBitmap.getWidth(), aBitmap.getHeight()); Log.debug("proper size: {}x{}", aWidth, aHeight); // #endif return bitmap; }
private void drawBrightnessIndicator(Canvas canvas) { // get a representation of the height of the indicator within the bar float brightnessHeight = mNewColor[2] * mWheel.getHeight(); // Log.d(TAG, String.format("Brightness height: %f", brightnessHeight)); // convert the height to an absolute y position based on the bar's position float absoluteY = mWheelPosition.y + mWheel.getHeight() - brightnessHeight; // get the y value "above" the x axis for the x coordinate calculation // note: because of symmetry, the sign doesn't matter so we'll use the positive float heightAboveXAxis = Math.abs(brightnessHeight - (float) mRadius); // Log.d(TAG, String.format("Height above X: %f", heightAboveXAxis)); float leftEdgeRadius = (float) (mRadius + SPACE_BETWEEN_WHEEL_AND_BAR); float rightEdgeRadius = leftEdgeRadius + ARC_WIDTH; // get the x coordinate relative to the center of the wheel float leftXInCircle = (float) Math.sqrt(leftEdgeRadius * leftEdgeRadius - heightAboveXAxis * heightAboveXAxis); float rightXInCircle = (float) Math.sqrt(rightEdgeRadius * rightEdgeRadius - heightAboveXAxis * heightAboveXAxis); // get the absolute x and y coordinates of the left edge of the bar at the bar height float leftX = mWheelCenter.x + leftXInCircle; float rightX = mWheelCenter.x + rightXInCircle; float indicatorHeight = BRIGHTNESS_INDICATOR_SIZE / 2.0f; float indicatorWidth = BRIGHTNESS_INDICATOR_SIZE; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStrokeWidth(1.0f); Path leftTrianglePath = new Path(); leftTrianglePath.moveTo(leftX, absoluteY - indicatorHeight); leftTrianglePath.lineTo(leftX + indicatorWidth, absoluteY); leftTrianglePath.lineTo(leftX, absoluteY + indicatorHeight); leftTrianglePath.close(); paint.setColor(Color.BLUE); paint.setStyle(Paint.Style.FILL); canvas.drawPath(leftTrianglePath, paint); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); canvas.drawPath(leftTrianglePath, paint); Path rightTrianglePath = new Path(); rightTrianglePath.moveTo(rightX, absoluteY - indicatorHeight); rightTrianglePath.lineTo(rightX - indicatorWidth, absoluteY); rightTrianglePath.lineTo(rightX, absoluteY + indicatorHeight); rightTrianglePath.close(); paint.setColor(Color.BLUE); paint.setStyle(Paint.Style.FILL); canvas.drawPath(rightTrianglePath, paint); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); canvas.drawPath(rightTrianglePath, paint); }
/** @Method: packData @Description: ���Ҫ���͵���� */ private void packData() { currentBitmap = BitmapList[firstView]; ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); // stream1 currentBitmap.compress( Bitmap.CompressFormat.PNG, 1, stream1); // compress to which format you want byte[] byte_arr = stream1.toByteArray(); // stream1 to byte try { stream1.close(); stream1 = null; } catch (IOException e1) { e1.printStackTrace(); } String image_str = Base64.encodeBytes(byte_arr); // byte to string Bitmap smallcurrentBitmap; float wRatio = (float) (currentBitmap.getWidth() / 100.0); float hRatio = (float) (currentBitmap.getHeight() / 100.0); if (wRatio > 1 && hRatio > 1) // ����ָ����С������С��Ӧ�ı��� { float scaleTemp; if (wRatio > hRatio) scaleTemp = hRatio; else scaleTemp = wRatio; wRatio = currentBitmap.getWidth() / scaleTemp; hRatio = currentBitmap.getHeight() / scaleTemp; int h = (int) wRatio; int w = (int) hRatio; smallcurrentBitmap = Bitmap.createScaledBitmap(currentBitmap, h, w, false); } else smallcurrentBitmap = currentBitmap; ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); // stream2 smallcurrentBitmap.compress( Bitmap.CompressFormat.PNG, 50, stream2); // compress to which format you want smallcurrentBitmap.recycle(); byte_arr = stream2.toByteArray(); // stream2 to byte try { stream2.close(); stream2 = null; } catch (IOException e) { e.printStackTrace(); } String smallimage_str = Base64.encodeBytes(byte_arr); // byte to string nameValuePairs.add(new BasicNameValuePair("protocol", "upload")); // ��װ��ֵ�� nameValuePairs.add(new BasicNameValuePair("id", LoginActivity.mineID)); nameValuePairs.add(new BasicNameValuePair("albumName", choosedAlbum)); nameValuePairs.add( new BasicNameValuePair( "imageName", PhotoAlbumActivity.AlbumsFloderName.get(AlbumName).get(currentNum))); Log.d("debug", PhotoAlbumActivity.AlbumsFloderName.get(AlbumName).get(currentNum)); nameValuePairs.add(new BasicNameValuePair("image", image_str)); nameValuePairs.add(new BasicNameValuePair("smallImage", smallimage_str)); System.gc(); }
public static Bitmap matrixBmp(Bitmap bmp, int margin) { int width = bmp.getWidth(); int height = bmp.getHeight(); int px = UIUtils.dipToPx(margin); Matrix matrix = new Matrix(); if (width > UIUtils.getWidth() - px) { float scale = ((float) (UIUtils.getWidth() - px) / width); matrix.postScale(scale, scale); } else { matrix.postScale(1, 1); } return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); }