Сохранить растровое изображение в местоположении

взгляните на этот пример

class Person
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Phone { get; set; }
}

class Pet
{
    public string Name { get; set; }
    public Person Owner { get; set; }
}

public static void LeftOuterJoinExample()
{
    Person magnus = new Person {ID = 1, FirstName = "Magnus", LastName = "Hedlund"};
    Person terry = new Person {ID = 2, FirstName = "Terry", LastName = "Adams"};
    Person charlotte = new Person {ID = 3, FirstName = "Charlotte", LastName = "Weiss"};
    Person arlene = new Person {ID = 4, FirstName = "Arlene", LastName = "Huff"};

    Pet barley = new Pet {Name = "Barley", Owner = terry};
    Pet boots = new Pet {Name = "Boots", Owner = terry};
    Pet whiskers = new Pet {Name = "Whiskers", Owner = charlotte};
    Pet bluemoon = new Pet {Name = "Blue Moon", Owner = terry};
    Pet daisy = new Pet {Name = "Daisy", Owner = magnus};

    // Create two lists.
    List people = new List {magnus, terry, charlotte, arlene};
    List pets = new List {barley, boots, whiskers, bluemoon, daisy};

    var query = from person in people
        where person.ID == 4
        join pet in pets on person equals pet.Owner  into personpets
        from petOrNull in personpets.DefaultIfEmpty()
        select new { Person=person, Pet = petOrNull}; 



    foreach (var v in query )
    {
        Console.WriteLine("{0,-15}{1}", v.Person.FirstName + ":", (v.Pet == null ? "Does not Exist" : v.Pet.Name));
    }
}

// This code produces the following output:
//
// Magnus:        Daisy
// Terry:         Barley
// Terry:         Boots
// Terry:         Blue Moon
// Charlotte:     Whiskers
// Arlene:

, теперь вы можете include elements from the left, даже если этот элемент has no matches in the right, в нашем случае мы восстановили Arlene, даже если он не имеет соответствия в правой

здесь ссылка

Практическое руководство. Выполнение левых внешних соединений (руководство по программированию на C #)

449
задан Sergey Glotov 13 March 2013 в 16:32
поделиться

4 ответа

try (FileOutputStream out = new FileOutputStream(filename)) {
    bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
    // PNG is a lossless format, the compression factor (100) is ignored
} catch (IOException e) {
    e.printStackTrace();
}
885
ответ дан xcuipir 14 March 2013 в 03:32
поделиться

Почему бы не звонить Bitmap.compress метод с 100 (то, которое походит на него, без потерь)?

7
ответ дан Bhushan Firake 14 March 2013 в 03:32
поделиться

Некоторые форматы, например PNG без потерь, будут игнорировать настройку качества.

13
ответ дан 22 November 2019 в 23:01
поделиться

Вы должны использовать метод Bitmap.compress() для сохранения Bitmap в файл. Он сожмет (если это позволяет используемый формат) ваше изображение и выведет его в OutputStream.

Вот пример экземпляра Bitmap, полученного через getImageBitmap(myurl), который может быть сжат как JPEG со степенью сжатия 85% :

// Assume block needs to be inside a Try/Catch block.
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
Integer counter = 0;
File file = new File(path, "FitnessGirl"+counter+".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten.
fOut = new FileOutputStream(file);

Bitmap pictureBitmap = getImageBitmap(myurl); // obtaining the Bitmap
pictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate
fOut.flush(); // Not really required
fOut.close(); // do not forget to close the stream

MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
131
ответ дан 22 November 2019 в 23:01
поделиться
Другие вопросы по тегам:

Похожие вопросы: