Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Bitmap from view with opaque/semi transparent background

Bitmap from view with opaque/semi transparent background

Scheduled Pinned Locked Moved Android
csharpcomgraphicshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #1

    I'm using the code below to create a filled rounded rectangle with border of a view. The problem is: 1. If Alpha is set high, the bitmap of the view is no longer visible 2. If Alpha is medium, the bitmap of the view is also dulled I want the foreground to be as the original on top of the background that is controlled by the Alpha value

        Bitmap bitmap = getBitmapFromView(view);
        Canvas canvas = new Canvas(bitmap);
        Paint background = new Paint();
        RectF rectF = new RectF(1, 1, bitmap.getWidth() - 2, bitmap.getHeight() - 2);
        
        // draw background
        background.setStyle(Paint.Style.FILL);
        background.setColor(BACKGROUND\_COLOUR);
        background.setAlpha(ALPHA);
        canvas.drawRoundRect(rectF, ROUNDING, ROUNDING, background);
        
        // draw border
        background.setStyle(Paint.Style.STROKE);
        background.setStrokeWidth(LINE\_THICKNESS);
        background.setColor(BORDER\_COLOUR);
        canvas.drawRoundRect(rectF, ROUNDING, ROUNDING, background);
        
        // draw foreground
        Paint foreground = new Paint();
        canvas.drawBitmap(bitmap, 0, 0, foreground);
        
        return bitmap;
    

    Dave
    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

    H 1 Reply Last reply
    0
    • D DaveyM69

      I'm using the code below to create a filled rounded rectangle with border of a view. The problem is: 1. If Alpha is set high, the bitmap of the view is no longer visible 2. If Alpha is medium, the bitmap of the view is also dulled I want the foreground to be as the original on top of the background that is controlled by the Alpha value

          Bitmap bitmap = getBitmapFromView(view);
          Canvas canvas = new Canvas(bitmap);
          Paint background = new Paint();
          RectF rectF = new RectF(1, 1, bitmap.getWidth() - 2, bitmap.getHeight() - 2);
          
          // draw background
          background.setStyle(Paint.Style.FILL);
          background.setColor(BACKGROUND\_COLOUR);
          background.setAlpha(ALPHA);
          canvas.drawRoundRect(rectF, ROUNDING, ROUNDING, background);
          
          // draw border
          background.setStyle(Paint.Style.STROKE);
          background.setStrokeWidth(LINE\_THICKNESS);
          background.setColor(BORDER\_COLOUR);
          canvas.drawRoundRect(rectF, ROUNDING, ROUNDING, background);
          
          // draw foreground
          Paint foreground = new Paint();
          canvas.drawBitmap(bitmap, 0, 0, foreground);
          
          return bitmap;
      

      Dave
      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      H Offline
      H Offline
      hhsumon
      wrote on last edited by
      #2

      I am trying to use your valuable code but it gives me some errors . 03-31 11:57:20.533: W/dalvikvm(2117): threadid=11: thread exiting with uncaught exception (group=0xa4c35648) 03-31 11:57:20.533: E/AndroidRuntime(2117): FATAL EXCEPTION: Thread-183 03-31 11:57:20.533: E/AndroidRuntime(2117): java.lang.UnsupportedOperationException 03-31 11:57:20.533: E/AndroidRuntime(2117): at java.lang.Thread.stop(Thread.java:1052) 03-31 11:57:20.533: E/AndroidRuntime(2117): at java.lang.Thread.stop(Thread.java:1042) 03-31 11:57:20.533: E/AndroidRuntime(2117): at com.yourname.main.SplashScreen$2.run(SplashScreen.java:59) What is the problem? I download & run your project dmo so there is no chance to mistake myself .

      D 1 Reply Last reply
      0
      • H hhsumon

        I am trying to use your valuable code but it gives me some errors . 03-31 11:57:20.533: W/dalvikvm(2117): threadid=11: thread exiting with uncaught exception (group=0xa4c35648) 03-31 11:57:20.533: E/AndroidRuntime(2117): FATAL EXCEPTION: Thread-183 03-31 11:57:20.533: E/AndroidRuntime(2117): java.lang.UnsupportedOperationException 03-31 11:57:20.533: E/AndroidRuntime(2117): at java.lang.Thread.stop(Thread.java:1052) 03-31 11:57:20.533: E/AndroidRuntime(2117): at java.lang.Thread.stop(Thread.java:1042) 03-31 11:57:20.533: E/AndroidRuntime(2117): at com.yourname.main.SplashScreen$2.run(SplashScreen.java:59) What is the problem? I download & run your project dmo so there is no chance to mistake myself .

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        No idea I'm afraid without seeing your code... You need to put a breakpoint at line 59 in SplashScreen.java and see what's going wrong

        Dave
        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups