Code example for Bitmap

Methods: createBitmapcreateScaledBitmapgetHeightgetWidthrecycle

0
            		artistName + 
            		" - " + 
            		albumName);
             
            views.setImageViewBitmap(R.id.album_cover, albumCover);
            albumCoverCrude.recycle();   
        } 
         
        // Set correct drawable for pause state 
        final boolean playing = service.isPlaying();
//        if (playing) { 
//            views.setImageViewResource(R.id.control_play, R.drawable.appwidget_pause); 
//        } else { 
//            views.setImageViewResource(R.id.control_play, R.drawable.appwidget_play); 
//        } 
// 
        // Link actions buttons to intents 
        linkButtons(service, views, playing);
//         
        pushUpdate(service, appWidgetIds, views);
    } 
 
    /** 
     * Link up various button actions using {@link PendingIntents}. 
     *  
     * @param playerActive True if player is active in background, which means 
     *            widget click will launch {@link MediaPlaybackActivity}, 
     *            otherwise we launch {@link MusicBrowserActivity}. 
     */ 
    private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
        // Connect up various buttons and touch events 
        Intent intent;
        PendingIntent pendingIntent;
         
        final ComponentName serviceName = new ComponentName(context, PlayerService.class);
         
        if (playerActive) {
            intent = new Intent(context, RockPlayer.class);
            pendingIntent = PendingIntent.getActivity(context,
                    0 /* no requestCode */, intent, 0 /* no flags */);
            views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent);
        } else { 
            intent = new Intent(context, RockPlayer.class);
            pendingIntent = PendingIntent.getActivity(context,
                    0 /* no requestCode */, intent, 0 /* no flags */);
            views.setOnClickPendingIntent(R.id.album_appwidget, pendingIntent);
        } 
//         
            
////        intent = new Intent(PlayerService.TOGGLEPAUSE_ACTION); 
 
////        intent = new Intent(MediaPlaybackService.NEXT_ACTION); 
        Intent intentNext = new Intent(PlayerService.SERVICECMD);
        intentNext.putExtra(PlayerService.CMDNAME,
        		PlayerService.CMDNEXT); 
        intent.replaceExtras(intentNext);
        intent.setComponent(serviceName);
        PendingIntent pendingIntentNext = PendingIntent.getService(context,
                0 /* no requestCode */, intent, 0 /* no flags */);
        views.setOnClickPendingIntent(R.id.control_next, pendingIntentNext);
 
         
		intent = new Intent(PlayerService.SERVICECMD);
		intent.putExtra(PlayerService.CMDNAME,
			PlayerService.CMDTOGGLEPAUSE); 
		intent.setComponent(serviceName);
		pendingIntent = PendingIntent.getService(context,
		    0 /* no requestCode */, intent, 0 /* no flags */);
		views.setOnClickPendingIntent(R.id.album_cover, pendingIntent);
		 
    } 
     
     
     
     
     
     
    Shader shader;
    RectF	rect = new RectF();
    Paint	paint= new Paint();
     
    /********************************* 
     *  
     * createFancyAlbumCover 
     *  
     *********************************/ 
//    Bitmap cBitmap = Bitmap.createBitmap(460, 460, Bitmap.Config.ARGB_8888); 
    public Bitmap createFancyAlbumCover(Bitmap bitmap, int width, int height){
 
    	try{ 
 
    		/* 
    		 * Adjust the aspect ratio of the incoming bitmap if needed 
    		 */ 
    		float aspectRatio = (float)width/(float)height; 
    		if(Math.abs(aspectRatio - ((float)bitmap.getWidth()/(float)bitmap.getHeight())) > 0.1){
        		 
    			if(aspectRatio > 1){ // width is larger
	    			bitmap = Bitmap.createBitmap(
		        				bitmap,
		        				0, 
		        				(int)(bitmap.getHeight()-(bitmap.getHeight()/aspectRatio))/2,
		        				bitmap.getWidth(),
		        				(int)(bitmap.getHeight()/aspectRatio));
    			} else { 
					bitmap = Bitmap.createBitmap(
	        				bitmap,
	        				(int)(bitmap.getWidth()-(bitmap.getWidth()*aspectRatio))/2,
	        				0, 
	        				(int)(bitmap.getWidth()*aspectRatio),
	        				bitmap.getHeight());
    			} 
    		} 
    		 
	//    	Bitmap tBitmap; 
	    	paint.setAntiAlias(true);
	    	paint.setDither(true);
	    	//BlurMaskFilter blurFilter = new BlurMaskFilter(viewWidth/20.0f, BlurMaskFilter.Blur.INNER); 
	    	 
	        Bitmap cBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	        Canvas canvas = new Canvas();
	        canvas.setBitmap(cBitmap); 
	         
	//        //paint.setXfermode(new PorterDuffXfermode(Mode.)); 
	//        paint.setMaskFilter(blurFilter); 
	//	  	//paint.setAlpha(100); 
	//	  	tBitmap = Bitmap.createScaledBitmap(bitmapDecoder.decodeFile(path), 
	//	  		width, height, false); 
	//	  	canvas.drawBitmap(tBitmap, 0, 0, paint); 
	//	 
	//	     
	//		paint.setXfermode(new PorterDuffXfermode(Mode.LIGHTEN));  
	//		paint.setAlpha(150); 
	//		tBitmap = Bitmap.createScaledBitmap(bitmapDecoder.decodeFile(path), 
	//				width, height, false); 
	//		canvas.drawBitmap(tBitmap, 0, 0, paint); 
	 
			//paint.setXfermode(new PorterDuffXfermode(Mode.DARKEN)); 
	         
	        paint.setXfermode(null);
	        if(bitmap != null){
		        Shader bmpShader = new BitmapShader(
		        		Bitmap.createScaledBitmap(
		        				bitmap,
		        				width, 
		        				height, 
		        				false), 
	//	        		bitmap, 
Experience pair programming with AI  Get Codota for Java