Make an Image Compressor App | Android Project | Full Tutorial

Make an Image Compressor App | Android Project | Full Tutorial

Coding With Evan

3 года назад

17,956 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@نوشینروستائی
@نوشینروستائی - 25.05.2021 13:21

Help me please

Ответить
@technologytv1810
@technologytv1810 - 26.05.2021 18:17

Can we add ad mob ads

Ответить
@technologytv1810
@technologytv1810 - 26.05.2021 18:18

Please make a video to integrate ad mob in same app

Ответить
@varunshiremat
@varunshiremat - 30.05.2021 12:27

it show image is not sellected

Ответить
@kothapellijithender6202
@kothapellijithender6202 - 01.06.2021 14:11

I added dependency but but it does not showing any options like setMaxWidth, setMaxHeight...

Here is my code
@Override
public void onClick(View p1)
{
int quality=seekbar.getProgress();
int height=Integer.parseInt(edx1.getText().toString());
int width=Integer.parseInt(edx2.getText().toString());

compressedImage =new Compressor(MainActivity.this)


}
});

Ответить
@نوشینروستائی
@نوشینروستائی - 01.06.2021 22:29

Ah i have another error! When i click the compressor btn it show me somthing went wrong and the picture didnt compress why?

Ответить
@bearg7787
@bearg7787 - 08.06.2021 20:08

startActivityForResult(gallery, RESULT_IMAGE); -> is deprecated to me. Since I`m completely to those Libraries would be awesome if you had another way to do this ^^, thanks for the awesome project.

Ответить
@miracle.x1638
@miracle.x1638 - 11.06.2021 16:33

Dexter.withPermission error occuring
Cannot resolve withPermission

Ответить
@arpitvashistha8532
@arpitvashistha8532 - 11.06.2021 22:53

when I clicked on compress button i was not work. this is my java code help me to sort out this problem.
package com.example.imagecompressorapp;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.format.Formatter;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.karumi.dexter.Dexter;
import com.karumi.dexter.DexterBuilder;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import id.zelory.compressor.Compressor;


public class MainActivity extends AppCompatActivity {

public static final int RESULT_IMAGE = 1;

ImageView imgOriginal,imgCompress;
TextView txtOriginal,textCompress,txtQuality;
EditText txtHeight,txtWidth;
SeekBar seekBar;
Button btnPick,btnCompress;
File originalImage,compressImage;
private static String filepath;
File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myAppCompressor");


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

askPermission();
imgOriginal = findViewById(R.id.imgOriginal);
imgCompress = findViewById(R.id.imgCompress);
txtOriginal = findViewById(R.id.txtOriginal);
textCompress = findViewById(R.id.txtCompress);
txtQuality = findViewById(R.id.txtQuality);
txtHeight = findViewById(R.id.txtHeight);
txtWidth = findViewById(R.id.txtWidth);
seekBar = findViewById(R.id.seekQuality);
btnPick = findViewById(R.id.btnPick);
btnCompress = findViewById(R.id.btnCompresd);

filepath = path.getAbsolutePath();

if(!path.exists())
{
path.mkdirs();
}

// seekbar

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {
txtQuality.setText("Quality: "+ i);
seekBar.setMax(100);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

// Pick image from gallery

btnPick.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {

openGallery();
}
});

// compress function start

btnCompress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int quality = seekBar.getProgress();
int width = Integer.parseInt(txtWidth.getText().toString());
int height = Integer.parseInt(txtHeight.getText().toString());

try {
compressImage = new Compressor(MainActivity.this)
.setMaxWidth(width)
.setMaxHeight(height)
.setQuality(quality)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setDestinationDirectoryPath(filepath)
.compressToFile(originalImage);

File finalFile = new File(filepath,originalImage.getName());
Bitmap finalBitmap = BitmapFactory.decodeFile(finalFile.getAbsolutePath());
imgCompress.setImageBitmap(finalBitmap);
textCompress.setText("Size: "+Formatter.formatShortFileSize(MainActivity.this,finalFile.length()));

Toast.makeText(MainActivity.this, "Image Compressed && Saved!!", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error while Compress", Toast.LENGTH_SHORT).show();f
}
}
});
}

private void openGallery() {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery,RESULT_IMAGE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode== RESULT_OK)
{
btnCompress.setVisibility(View.VISIBLE);
final Uri imageUri = data.getData();
try {
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
imgOriginal.setImageBitmap(selectedImage);
originalImage = new File(imageUri.getPath().replace("raw/",""));
txtOriginal.setText("Size"+ Formatter.formatShortFileSize(this,originalImage.length()));
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Something Went Wrong!", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(this, "No Image Selected!", Toast.LENGTH_SHORT).show();
}
}

private void askPermission() {
Dexter.withContext(this)
.withPermissions(Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {

}

@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
permissionToken.continuePermissionRequest();

}
}).check();

}
}

Ответить
@NaelEno
@NaelEno - 12.06.2021 14:52

thank you for this nice tutorial, is it compatible with android 11 scoped storage. can you test it on android 11 device. thanks

Ответить
@arijitmajumdar7787
@arijitmajumdar7787 - 13.06.2021 15:59

Image compressor original size showing o kb all time
why???

Ответить
@varunshenoy07
@varunshenoy07 - 16.06.2021 17:25

I am getting a stroke on "startActivityForResult".and even if i select an image , it says no image selected... Please Help me

Ответить
@anvitdubey5002
@anvitdubey5002 - 17.06.2021 01:07

I am getting error while saving and can't resolve it help please

Ответить
@trendTV24
@trendTV24 - 17.06.2021 22:37

I am not working Compressor
Please help me

Ответить
@hrishikeshpator3853
@hrishikeshpator3853 - 20.06.2021 22:45

Source code please.....

Ответить
@ritikaswaraj5574
@ritikaswaraj5574 - 21.06.2021 21:47

Why it is showing error in dexter

Ответить
@yteewsgaming7756
@yteewsgaming7756 - 15.07.2021 14:42

when click on an image its showing no image selected

Ответить
@sabarish8150
@sabarish8150 - 17.07.2021 15:52

Not image Selected😥

Ответить
@nicktrixs
@nicktrixs - 18.07.2021 14:10

Bro how can I select multiple images,,, please reply bro

Ответить
@FUTUREGC-q6f
@FUTUREGC-q6f - 23.07.2021 12:36

hey bro i watched your whole tutorial ,does everything same but when i m clickng on compressed button it is showing error.
i notice that while your were coding u used differnt emulator and after finishing u used diffrent

Ответить
@harushar3825
@harushar3825 - 27.07.2021 13:58

Image compressor original size is showing 0Kb every time. Can You please help me out!

Ответить
@dilhaque4614
@dilhaque4614 - 03.08.2021 19:42

Brw is this project start in empty activity

Ответить
@dilhaque4614
@dilhaque4614 - 07.08.2021 11:30

Brw mkdir path not working😢😢

Ответить
@fitncode
@fitncode - 09.08.2021 20:22

StartActivityForResult is depricated

Ответить
@Ankur-zd4db
@Ankur-zd4db - 08.09.2021 16:03

Sir btncompress button click krne par error aa raha hai. ( Error while compressing ). Please help me sir

Ответить
@vgaming5780
@vgaming5780 - 29.09.2021 15:12

image size hamesha 0 bata rha he then show error while compressing.. help me..

Ответить
@minaganvit3856
@minaganvit3856 - 27.10.2021 19:46

When I take image it show size zero byte and when I trying to compress then it crashed. Why this things are happening?

Ответить
@kawsarahmedbappi2995
@kawsarahmedbappi2995 - 30.11.2021 05:40

tnx, kindly tell me
this is java or kotlin????

Ответить
@kitebelajar3729
@kitebelajar3729 - 02.12.2021 19:09

i want ask you about this app, in this app using algorithm ? huffman coding ?? or something ??

Ответить
@amosbanda9657
@amosbanda9657 - 09.01.2022 12:30

thanks for the vid , is their a link to the source code

Ответить
@harisai3580
@harisai3580 - 15.01.2022 09:58

Brother, you are great. Explained very nicely, Thankyou so much. I am subsribing right away.

Ответить
@ROHITKUMAR-pn4gj
@ROHITKUMAR-pn4gj - 28.01.2022 02:03

Compressor()' has private access in 'id.zelory.compressor.Compressor'


when i tried to make and object its of Compressoe its showing Error

Ответить
@iteacherarmy
@iteacherarmy - 14.03.2022 06:47

Thanks for the amazing tutorial

Ответить
@im_dev_alok
@im_dev_alok - 13.04.2022 11:53

Brother, you are great but can u make a video on string compression. Please!

Ответить
@harshanagendra8156
@harshanagendra8156 - 26.04.2022 10:14

Project is awesome. I learnt so much from your Tutorial. Kindly provide source code.

Ответить
@sunilrio2823
@sunilrio2823 - 02.05.2022 12:06

Size of the image is not showing and compressor error can anyone tell me the solution

Ответить
@TheFamefight
@TheFamefight - 06.06.2022 15:23

sir, what algorithms is this ? Huffman or LZW ?
kindly tell me pls

Ответить
@promoteprovider1218
@promoteprovider1218 - 06.06.2022 20:31

Size of the image is not showing and compressor error can anyone tell me the solution??

Ответить
@ambermughal5518
@ambermughal5518 - 02.08.2022 15:21

Kindly sir share this apk file

Ответить
@dekhoindia4173
@dekhoindia4173 - 22.08.2022 16:29

I don't show original images size please help me

Ответить
@anchaljain9951
@anchaljain9951 - 13.09.2022 20:42

can you answer which technique you have used in this app

Ответить
@kojagirdevelopers
@kojagirdevelopers - 15.10.2022 16:49

Sir, WRITE EXTERNAL STORAGE is not working above Android 10+ , what will do, please response

Ответить
@kojagirdevelopers
@kojagirdevelopers - 20.10.2022 12:23

Hi sir, not able to write internal storage in about Android 10+

Ответить
@siddhinivale8649
@siddhinivale8649 - 08.02.2023 21:40

It Doesn't show the image size ...n when click on compress button it display the toast error

Ответить
@sonusajith3071
@sonusajith3071 - 24.09.2023 14:30

How to get the above application source code ❗❗

Ответить
@filokalos2001
@filokalos2001 - 14.10.2023 00:34

It is a great app. I followed you until I discovered that it is written for a java project (Minute 10 and so on). I´am a kotlin student. Thanks, anyway.

Ответить
@yesman3442
@yesman3442 - 19.12.2023 21:18

I have an erro, "Error while compressing image".

Ответить
@simplegamer7093
@simplegamer7093 - 06.03.2024 16:17

error while compressing
I think there is problem in android library, not updated yet
even not showing the size , many user has same problem in comment section⬆⬆⬆⬆

Ответить
@ElyasSayle
@ElyasSayle - 22.05.2024 19:04

aint no way your name is evan

Ответить