Android Question Create a transparent JPG files with white background

AlpVir

Well-Known Member
Licensed User
Longtime User
The following code creates a JPG file with white background :
B4X:
Dim C           As Canvas
Dim Rect1    As Rect
Dim BMPM        As Bitmap 
BMPM.InitializeMutable(W,H)
C.Initialize2 (BMPM)
Rect1.Initialize(0,0,W-1,H-1)
C.DrawRect(Rect1,Colors.RGB(255,255,255),True,100dip) 
   
Dim Out     As OutputStream
Out = File.OpenOutput (File.DirRootExternal , "test.jpg",False )
C.Bitmap.WriteToStream (Out,100,"JPEG")
Out.Close

Why replacing statement
B4X:
C.DrawRect(Rect1,Colors.RGB(255,255,255),True,100dip)
with
B4X:
C.DrawRect(Rect1,Colors.ARGB(0,255,255,255),True,100dip)
you do not create a transparent JPG files with white background ?
Thanks in advance.
 

JordiCP

Expert
Licensed User
Longtime User
However I checked just now that Photoshop can create JPG files with transparency !!!
I also thought it was impossible...have googled for it
If you are refering to JPEG 2000 (.jp2 or .jpx, but not .jpg or .jpeg) yes it allows transparency, but it "seems" that it is not widely supported (yet?)
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
With Photoshop in no time you can create an image with transparencies. Possible that you can not do the same with B4A ?
I attach a JPG image created with Photoshop and a PNG with transparent background, just as I want.
 

Attachments

  • PNG.png
    PNG.png
    13.3 KB · Views: 293
  • Transparent.jpg
    Transparent.jpg
    26.8 KB · Views: 268
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I can't see any transparency in your "Transparent.jpg" file --> does it have alpha channel?.

Not sure to understand exactly which is your concern

  • If you want to create transparent images with B4A in no time --> as Klaus said save them as PNG
B4X:
Dim C As Canvas
Dim Rect1 As Rect
Dim BMPM As Bitmap 
BMPM.InitializeMutable(W,H)
C.Initialize2 (BMPM)
Rect1.Initialize(0,0,W-1,H-1)
C.DrawRect(Rect1,Colors.Transparent,True,100dip) 
C.DrawText("Happy 2017", 0, 0,Typeface.DEFAULT,20,Colors.Green,"LEFT")
Dim Out As OutputStream
Out = File.OpenOutput (File.DirRootExternal , "test.png",False )
C.Bitmap.WriteToStream (Out,100,"PNG")
Out.Close
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
After extensive research I concluded that (as I was told in this forum) JPG format does not support transparency !
Evidently with Photoshop you can create pseudo-transparency as I have shown in a picture attached to the post # 7. This led me into error in thinking that it could create JPG images with transparent backgrounds.
Thanks to all of the support
 
Upvote 0
Top